-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Conditional types throw error since TS 4.9.x #51614
Comments
Workaround: |
This is working as intended. In cases where the outcome of a conditional type is known to always be the false branch, we no longer pretend that the type in the true branch has satisfied the type T0 = Number extends String ? Number["length"] : String["length"]; // This was previously ok but now errors I understand there's a possible usage pattern where the conditional type is a form of conditional compilation based on types declared elsewhere in the program, but in those cases I think it is reasonable to require an explicit intersection: type B = A extends Record<'foo', string> ? (A & Record<'foo', string>)['foo'] : string; |
@ahejlsberg what about interface augmentation though? With it, the type checker can't actually prove that the outcome of this conditional type is always its false branch. The conditional type can live in the library's code and the augmentation might happen in the consuming application. It seems that this is exactly how this was used here. In general, I agree with your reasoning but when providing the fix, I assumed that this was meant to be supported exactly because of the interface augmentation. |
Yeah, although unintended, I agree that's meaningful scenario. Let's call this a regression then and merge your PR. |
Bug Report
π Search Terms
conditional types, 2339
π Version & Regression Information
β― Playground Link
Playground link with relevant code and test cases
π» Code
π Actual behavior
errors with 2339:
Property 'foo' does not exist on type 'A'.
This change causes @vuejs/pinia to fail as one can see in vuejs/pinia#1814
π Expected behavior
returns with
B
being an alias for typestring
.The text was updated successfully, but these errors were encountered: