You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently typescript-is fails with Failed to transform node when trying to index type using a generic type
This happens on latest master (0.19.0)
Issue reproduction
Both of these tests will fail
exportconstStatus={enable: 'enable',disable: 'disable'}asconst;typeStatusObject<Keyextends'enable'|'disable'>={status: (typeofStatus)[Key];};describe('is',()=>{describe('Accessing generic member of a type',()=>{it('should return true for the right member',()=>{assert.deepStrictEqual(is<StatusObject<'enable'>>({status: Status.enable}),true);});it('should return false for the wrong member',()=>{assert.deepStrictEqual(is<StatusObject<'enable'>>({status: Status.disable}),false);});});});
In fact, it looks like this case affects any usage of typeof. For example, the following code works just fine:
typeFoo={foo: 0};is<Foo>('foo');// false
However, this fails
constobj={foo: 0};is<typeofobj>('foo');// throws an exception
Suggested fix
I think the fix is as simple as switching the priority of the condition here: check type first and THEN check valueDeclaration. This passes all existing tests and also fixes the two typeof issues I mentioned above.
Description
Currently typescript-is fails with
Failed to transform node
when trying to index type using a generic typeThis happens on latest master (0.19.0)
Issue reproduction
Both of these tests will fail
Investigation
Specific issue in this case
Currently, the code will throw on
typescript-is/src/transform-inline/visitor-utils.ts
Line 78 in 0dbefd0
TypeParameter
which doesn't match either case.It looks like the cause of this issue is that
TypeParameter
contains both avalueDeclaration
AND atype
memberGeneral case
In fact, it looks like this case affects any usage of
typeof
. For example, the following code works just fine:However, this fails
Suggested fix
I think the fix is as simple as switching the priority of the condition here: check
type
first and THEN checkvalueDeclaration
. This passes all existing tests and also fixes the twotypeof
issues I mentioned above.Related issues
Possible #59 #97 #103
The text was updated successfully, but these errors were encountered: