Closed kasperisager closed 5 years ago
This is an intentional cutoff to prevent later steps from becoming too combinatorially explosive.
I should add that prior to 3.4, this didn't even work for n = 2
π
Alright, that seems fair then π It would be nice with some more transparency around cases like this though, similar to how the compiler complains when union types become too complex. It wasn't immediately obvious why the compiler started complaining when the 26th case was added to the actual code π
Thanks for the answer!
I agree it'd be nice. Unfortunately this happens deep inside assignability checking and there might not actually end up being a downstream error when the assignability check fails as in this case, so it'd sometimes issue false positive errors unless we had some more formal causality analysis built in to the typechecking process.
TypeScript Version: 3.5.1
Search Terms:
25 union members, narrow union
Code
Expected behavior:
I would expect
{ type }
to be narrowed toT1 | T2 | ... | T26
and the code compile.Actual behavior:
TypeScript instead infers
{ type }
to beT
and fails to compile asT27
also requires avalue
property. However, if any of the cases are removed in order to bring the number of union type members down to 25, TypeScript correctly narrows{ type }
toT1 | T2 | ... | T25
(assumingT26
was removed) and compiles the code.Playground Link: https://www.typescriptlang.org/play/index.html#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgFQEY4BvOGATzGAC44AiGQ+uAXwChRJZEU0tcBAEylyVWgxhCWHLtHjJUGHHnwBmUZWp1GamZ3DzeSgaoAsm8Tphn9cnov4qCAVkvbJLu4Yd9lg-AA2dwlGQO9uBT9TAgB2EOtYiKNHf1UADgTJdOTfE2d8AE4sxkLcqPyAwgAGEqZq8uMnKuIyLVCmZjYDSKa0gkIRNqtJQcbUmKINYY9GQj1u+wrm1UILGY618eiCwjcN6z3tytXgg9HwxZ9l-qJ487mkq96J3cyHphznlJ2q4o-CGVvnkVsJah8hA1gTdJkJWmJZlIurJrn1YUMER0hNJoWiCkJppjrATjqD8EJ1kTJBTSbchPsqYx6bTYWdGVJLiiXr9VEJ7uy+fQANxwABumAANgBXCRIKUAWwARmhuj0jO0CHAALwDOAAH2E+oIGgN+AsprcpuCpvipsypuKppqRqIxCdIidJoG5oGloG1oGtoG9oGjrBLrhEY9wi95J95L95ID5NiQvY7HQUqQ2BgCAgSDg8swAGtgAAKdp0ADOMCgyAA5gBKOj4I1yiUS0jsOA9uBVgDuCBg2AAFnAK+JG13ezO4NhMFW8HN6DRu7Oe-PF9SV2v15ulzA9Kv1xuFwfbMeT-vPDuT3Oz5Jwpe9w-GEln7Pr4wch+Z1+YGUv69v+NS3ler6dGBL5bnM0hAaeMFMEeu6fhBWzwfeiFHBhIFPihf5oe++HAWhP7EQhB6AlBqGIZC1EEbRzA4RB2L0SRtHIXe-40sxtFeLxB5CHhd4zlAwAwFKUAFhsbBpjOHAoWJElSXA7YSmmrBAA
Related Issues: