Repository navigation
[Bug] Conditional types throw error since TS 4.9.xΒ #51614
Description
Activity
MartinJohns commented
on Nov 21, 2022 ContributorMore actionsWorkaround:
A extends Record<'foo', infer X extends string> ? X : stringReacted by Jan and SancheZzThis 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
extendscheck. In the example that produces an error above, the outcome of the conditional type is always the false branchstring, and in the true branch we no longer pretend it is possible to writeA['foo']because that property is known not to exist. I think this is preferable to allowing nonsense like this: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;
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Dec 6, 2022 Andarist commented
on Dec 6, 2022 ContributorMore actionsAnders Hejlsberg (@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.
what about interface augmentation though?
Yeah, although unintended, I agree that's meaningful scenario. Let's call this a regression then and merge your PR.
- addedBugA bug in TypeScriptA bug in TypeScriptand removedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Dec 7, 2022 - locked as resolved and limited conversation to collaborators
on Oct 22, 2025
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
Bbeing an alias for typestring.