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
No type error is reported and ret is inferred as unknown type.
π Expected behavior
I think a type error is reported because the call to f attempts to concretize the type variable X not only as a number but also as a string. In fact, TypeScript 4.9.5 reported a type error.
Additional information about the issue
I am not sure that TypeScript 4.9.5 was perfect. The following code is inferred to be unknown, but I think string is correct. This behavior was back to TypeScript 3.5.1.
constf=<X,>(g: <A,>(b: X)=>X,s: X)=>g(s);constret=f(<B,>(x: B)=>x,"str");// ^? const ret: unknown// actual: ret is inferred as unknown// expected: ret is inferred as string
I also found a strange behavior that a type variable that should have been concretized was returned without being concretized. I thought this is related, but I could be wrong. Sorry if so.
constf=<X,>(g: <A,>(x: X)=>X)=>g<string>;consth=f<number>(<B,>(x: number)=>1);// ^? const h: (x: X) => Xh(1);// actual: type error// expected: no type error
π Search Terms
type variables unknown
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.3#code/MYewdgzgLgBAZjAvDAPADQDQD4AUBzALlQEFscAjItASiSxkxgitsXrxwmoG4AoX0JFgAnAKaxkcHCgBCZAB5EZregEYMMAETRhmnrwD0BmCZgA9APxA
π» Code
π Actual behavior
No type error is reported and
ret
is inferred asunknown
type.π Expected behavior
I think a type error is reported because the call to
f
attempts to concretize the type variable X not only as a number but also as a string. In fact, TypeScript 4.9.5 reported a type error.Additional information about the issue
I am not sure that TypeScript 4.9.5 was perfect. The following code is inferred to be
unknown
, but I thinkstring
is correct. This behavior was back to TypeScript 3.5.1.https://www.typescriptlang.org/play/?ts=5.7.3#code/MYewdgzgLgBAZjAvDAPADQDQD4AUBzALlQEFscAjItASiSxkxgitsXrxwmoG4AoX0JFgAnAKaxkcHCgBCZAB5EZrevIwwARNGEaevAPT6YxmAD0A-P0MwAhsCgBXGwBsiY2AEsIMD2DijhMQATW28HMABrMBAAdzADI1F5AAdRe1Egt3Efb19-QIzQpihhXzwgA
I also found a strange behavior that a type variable that should have been concretized was returned without being concretized. I thought this is related, but I could be wrong. Sorry if so.
https://www.typescriptlang.org/play/?ts=5.7.3#code/MYewdgzgLgBAZjAvDAPADQDQD4AUBzALlQEFscAPItASiSxhrpjxWgCcBLMPLAbgCh+oSLAAWSeCjABXALYAjAKZtcKAEJlKMGQuW1E9AIzUBAelMxLMAHoB+QaJzGzFgIbAo01wBsiUAJ4ADoowymwgbPzmoeTBHooAJkRgIDABwaFs4WxAA
The text was updated successfully, but these errors were encountered: