Repository navigation
Conditional type doesn't go to true or false branch.Β #48243
Description
Activity
MartinJohns commented
on Mar 14, 2022 ContributorMore actionsResolving of conditional types involving unbound generic type arguments is deferred. At that point the compiler doesn't know what
Action<P, T>resolves to, because the compiler doesn't know what typesPandTare.alexeymolchan commented
on Mar 14, 2022 AuthorMore actionsMartin Johns (@MartinJohns) thanks for clarification, but i still don't understand. why it doesn't know what result of conditional type if i'm telling it that T will extend Record<string, unknown>
MartinJohns commented
on Mar 14, 2022 ContributorMore actionsTcan still benever, asneveralso extendsRecord<string, unknown>. TypeScript simply does not resolve conditional types involving unbound generic types, even if theoretically in some specific corner cases it could.alexeymolchan commented
on Mar 14, 2022 AuthorMore actionsMartin Johns (@MartinJohns) playground but why this works ?
RyanCavanaugh commented
on Mar 14, 2022 MemberMore actionsif i'm telling it that T will extend Record<string, unknown>
Conditional types are not necessarily linear (meaning that they have predictable behavior between
Tand an a subtype ofT), and figuring out whether or not they are requires reasoning in the form of "Does any type exist such that this type would behave in the other way?", which is not very tractable.- 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 Mar 14, 2022 alexeymolchan commented
on Mar 14, 2022 AuthorMore actionsRyan Cavanaugh (@RyanCavanaugh) okey, but why [T] extends [never] and T extends never produce different results (you can see the example above) ?
Aliaksei Molchan (@alexeymolchan) https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
T extends ...distributes over unions.[T] extends [...]does not. The former is thus more likely to be deferred than the latter, since it can't know whether to enable the distributive behavior or not until it has a concrete type to work with.alexeymolchan commented
on Mar 14, 2022 AuthorMore actionsBruce Pascoe (@fatcerberus) as i see from playground where
T extends ...no defer occur and i can accessaction.meta. correct me please, if i'm wrong.alexeymolchan commented
on Mar 14, 2022 AuthorMore actionsMartin Johns (@MartinJohns) mapped type like this
type OptionsFlags<Type> = { [Property in keyof Type]: boolean; };will be deferred too ?MartinJohns commented
on Mar 14, 2022 ContributorMore actionsHow would the compiler know what the final type will look like without knowing what type
Tactually is?To be clear, generics in TS don't work like C++ templates. The compiler only looks at the body of a generic once and tries to determine if it will work for all possible combinations of type parameters, but these checks are necessarily conservative because it would be prohibitively expensive and/or complex to do otherwise.
typescript-bot commented
on Mar 17, 2022 ContributorMore actionsThis issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Bug Report
π Search Terms
generic conditional types
already checked https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs and #31751
π Version & Regression Information
3.9.7 / 4.6.2
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
properties from intersection are not accessible (conditional type doesn't resolve as true / false branch)
π Expected behavior
conditional type should go to false branch. correct my please if i'm wrong
Thanks in advance.