TypeScript Version: 3.1.0-dev.20180921 (next)
typescript@3.1.0-dev.20180914 <- works as expected.
typescript@3.1.0-dev.20180915 <- problem started to appear at that very version.
Search Terms:
generic inference regression
typeXY='x'|'y'constx: XY='x'interfaceOpt<T>{v: T}constfoo=<T>(v: T): Opt<T>=>({ v })constfoox=foo(x)// Opt<string> instead of Opt<XY> (Regression)constbar=<T>(v: T): Opt<typeofv>=>({ v })constbarx=bar(x)// Opt<string> instead of Opt<XY> (Regression)constbaz=<T>(v: T): T=>vconstbazx=baz(x)// 'x' (OK)Expected behavior:
Expected union type to be preserved
Actual behavior:
Union type is expanded to string
Playground Link:
This Playground Link demonstrate the CORRECT Behaviour (because previous typescript version is used in the playground)
http://www.typescriptlang.org/play/#src=type%20XY%20%3D%20'x'%20%7C%20'y'%0D%0Aconst%20x%3A%20XY%20%3D%20'x'%0D%0Ainterface%20Opt%3CT%3E%20%7B%0D%0A%20%20v%3A%20T%0D%0A%7D%0D%0Aconst%20foo%20%3D%20%3CT%3E(v%3A%20T)%3A%20Opt%3CT%3E%20%3D%3E%20(%7B%20v%20%7D)%0D%0Aconst%20foox%20%3D%20foo(x)%20%2F%2F%20Opt%3Cstring%3E%20instead%20of%20Opt%3CXY%3E%20(Regression)%0D%0A%0D%0Aconst%20bar%20%3D%20%3CT%3E(v%3A%20T)%3A%20Opt%3Ctypeof%20v%3E%20%3D%3E%20(%7B%20v%20%7D)%0D%0Aconst%20barx%20%3D%20bar(x)%20%2F%2F%20Opt%3Cstring%3E%20instead%20of%20Opt%3CXY%3E%20(Regression)%0D%0A%0D%0Aconst%20baz%20%3D%20%3CT%3E(v%3A%20T)%3A%20T%20%3D%3E%20v%0D%0Aconst%20bazx%20%3D%20baz(x)%20%2F%2F%20'x'%20(OK)%0D%0A
Related Issues:
I think this bug is very recent; I've not found anything relevant.
TypeScript Version: 3.1.0-dev.20180921 (next)
typescript@3.1.0-dev.20180914 <- works as expected.
typescript@3.1.0-dev.20180915 <- problem started to appear at that very version.
Search Terms:
generic inference regression
Expected behavior:
Expected union type to be preserved
Actual behavior:
Union type is expanded to
stringPlayground Link:
This Playground Link demonstrate the CORRECT Behaviour (because previous typescript version is used in the playground)
http://www.typescriptlang.org/play/#src=type%20XY%20%3D%20'x'%20%7C%20'y'%0D%0Aconst%20x%3A%20XY%20%3D%20'x'%0D%0Ainterface%20Opt%3CT%3E%20%7B%0D%0A%20%20v%3A%20T%0D%0A%7D%0D%0Aconst%20foo%20%3D%20%3CT%3E(v%3A%20T)%3A%20Opt%3CT%3E%20%3D%3E%20(%7B%20v%20%7D)%0D%0Aconst%20foox%20%3D%20foo(x)%20%2F%2F%20Opt%3Cstring%3E%20instead%20of%20Opt%3CXY%3E%20(Regression)%0D%0A%0D%0Aconst%20bar%20%3D%20%3CT%3E(v%3A%20T)%3A%20Opt%3Ctypeof%20v%3E%20%3D%3E%20(%7B%20v%20%7D)%0D%0Aconst%20barx%20%3D%20bar(x)%20%2F%2F%20Opt%3Cstring%3E%20instead%20of%20Opt%3CXY%3E%20(Regression)%0D%0A%0D%0Aconst%20baz%20%3D%20%3CT%3E(v%3A%20T)%3A%20T%20%3D%3E%20v%0D%0Aconst%20bazx%20%3D%20baz(x)%20%2F%2F%20'x'%20(OK)%0D%0A
Related Issues:
I think this bug is very recent; I've not found anything relevant.