I have a type inside a block, but I want to reference it from an external block. In this example I have a drizzle ORM query which generates a well defined type, which I want to use in the calling function:
function a() = {
const emisor = db.query.registro.findFirst({
where: eq(registro.nrc, '1234'),
with: {
actividad: true,
municipio: true
}
});
type Emisor = typeof emisor;
processDTE(emisor);
};
function processDTE(emisor){
// Do more stuff
}
Ideally I want to do something like function processDTE(emisor: Emisor)
but I cannot reference Emisor from an external block.
Editing to a minimal reproducible example:
function start() {
const variable = { a: 'Some object with a complex structure....' };
type myType = typeof variable;
process(variable);
}
function process(variable: myType) {
variable.a = 'Something';
}
I left drizzle in the first example, in case someone knows the "Drizzle" way to do this. But the main problem is that I want to use a type myType which was created inside a block, but I want to use it outside the block.
Of course this example function process(variable: myType)
will not work as myType is not scoped for this.