Hookyns/tst-reflect

Different Array<T> and Promise<T> types getting assigned the same metadata store id

Closed this issue · 7 comments

bjsi commented

I ran into an issue with using getType on arrays and promises.

const x = getType<string[]>().getTypeArguments()[0]; // returns string
const y  = getType<number[]>().getTypeArguments()[0] // also returns string

I cloned the library and ran in debug mode inside the test suite:

image

I think the problem is that string[] and number[] are getting assigned the same metadata store id.

Let me know if I can help in any way, maybe this is already fixed in the update you are working on.

I think I know what is going on.
You can try to fix, if you want. 🙂 I'm off for today...

The arrays are the same ts.Symbol probably so they have the same id.

export function getTypeId(type: ts.Type, typeChecker: ts.TypeChecker): number | undefined
{
const symbol = getTypeSymbol(type, typeChecker);
if (symbol == undefined)
{
return;
}
return getSymbolId(symbol);
}

In the new version I use type.id, not symbol.id, it should fix this issue, but it may cause other issues... Not every symbol has id but every type has. Only types with Id are stored, others are inlined... but it may not be an issue, but it will generate bigger metadata.

bjsi commented

Thanks, I'll play around and see if I can fix.

I'm working on it.

Return type's id instead of symbol's id is not enough. I've made several other changes to make it work, everything seems alright but two tests are failing. Those tests seems unrelated to this but idk there must be something,.. I'm trying to solve that.

Solved.

I've published tst-reflect-transformer@0.9.5.

bjsi commented

Awesome, looks like the issue is fixed for me!

@all-contributors please add @bjsi for bug report

@Hookyns

I've put up a pull request to add @bjsi! 🎉