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
typeTags={foo: '';bar: '';baz: '';}typeTag=keyofTagstypeGetTag<UsedTagextendskeyofTags>=keyof{[taginUsedTag]: any}typeDoThingVersionOne=<UsedTagextendsTag=Tag,Props={}>(tag: UsedTag)=>GetTag<UsedTag>constdoThingVersionOne: DoThingVersionOne={}asanyconstfooOne=doThingVersionOne('foo')// expected | type = "foo"constfooOneITag=doThingVersionOne<'foo'>('foo')// expected | type = "foo"constfooBarITagIProps=doThingVersionOne<'foo',{}>('foo')// expected | type = "foo"typeDoThingVersionTwo=<Props={},UsedTagextendsTag=Tag>(tag: UsedTag)=>GetTag<UsedTag>constdoThingVersionTwo: DoThingVersionTwo={}asanyconstfooTwo=doThingVersionTwo('foo')// expected | type = "foo"constfooTwoITag=doThingVersionTwo<{}>('foo')// unexpected | type "foo" | "bar" | "baz" constfooTwoITagIProps=doThingVersionTwo<{},'foo'>('foo')// expected | type "foo"
Expected behavior:
The order of a generic does not effect it's behaviour when narrowing from a union.
Actual behavior:
The order of a generic does effect it's behaviour when narrowing from a union.
As described below when no generics are passed typescript infers all of them, when any number of generics are passed typescript partially instantiates all of them using the defaults provided.
The text was updated successfully, but these errors were encountered:
luke-john
changed the title
Narrowing a union from generic fails based on when union is not the first generic
Narrowing a union from generic fails when union is not the first generic
Mar 30, 2018
The order matters because of the default values you have and in the unexpected case you're partially instantiating the generics. The following two are equivalent and give the same result.
I believe partial application of generics turns off inference for those that are omitted (they fall back to their default value). I guess the issue you're saying is that it should try and infer missing default type parameters?
TypeScript Version:
Search Terms:
Code
Expected behavior:
The order of a generic does not effect it's behaviour when narrowing from a union.
Actual behavior:
The order of a generic does effect it's behaviour when narrowing from a union.As described below when no generics are passed typescript infers all of them, when any number of generics are passed typescript partially instantiates all of them using the defaults provided.
Playground Link:
Playground Reproduction
Related Issues:
#17713
#21631
#12424
The text was updated successfully, but these errors were encountered: