You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A<"foo"> = 0 and B<"foo"> = 0.
Actually, these conditional branches are resolved at the time of type alias definition.
Then, any instantiation of A and B is 0
🙂 Expected behavior
Both A<"foo"> and B<"foo"> should be 1.
Conditional types in A and B should not be resolved during type alias definition, but should be deferred until an instantiation.
Additional information about the issue
Related
#52102 is similar.
This issue is about incorrect "simplification" involving intrinsic string mapping types.
More info
I did some investigation in codebase.
It looks like that the cause of the problem is handling of string mapping type in getGenericObjectFlags or isPatternLiteralPlaceholderType which was introduced in #52836 .
Yes, I admit that its more natural to use type constraints in above example.
In fact, I found this issue while using Lowercase combined with mapped type.
But it turned out that mapped type was not the cause of problem and I decided to use more simple example in above description.
Here is a more motivating example.
typeCamelCase<Sextendsstring>=Lowercase<S>extends `${infer S1}_${infer S2}` ? `${S1}${Capitalize<S2>}` : Lowercase<S>typeRenameKeys<T>={[KinkeyofTasCamelCase<K&string>]: T[K]}typeA=CamelCase<"foo_bar">// ^? type A = "fooBar"typeB=RenameKeys<{foo_bar: number}>// ^? type B = { foo_bar: number }// should be B = { fooBar: number }
Bug Report
🔎 Search Terms
lowercase, uppercase, intrinsic, conditional type
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.1.6#code/C4TwDgpgBAggPAZQHxQLxQDIHsDuEBOAxgIYDOEiAZKcPgJYB2A5ihAB7AQMAmpUARADMsWflAD8UAIxQAXFAAMAKAD0KqFAB64paEhQAQohTpseImQoJqtRiyjtOPPgANBAEgDeNeswC+LhLScoqq6lo6SgA2EMBQbFLy8EIi-CbBag74+Fj40bHxAEzyRimi6TKZBDn4QA
💻 Code
🙁 Actual behavior
A<"foo"> = 0
andB<"foo"> = 0
.Actually, these conditional branches are resolved at the time of type alias definition.
Then, any instantiation of
A
andB
is0
🙂 Expected behavior
Both
A<"foo">
andB<"foo">
should be1
.Conditional types in A and B should not be resolved during type alias definition, but should be deferred until an instantiation.
Additional information about the issue
Related
#52102 is similar.
This issue is about incorrect "simplification" involving intrinsic string mapping types.
More info
I did some investigation in codebase.
It looks like that the cause of the problem is handling of string mapping type in
getGenericObjectFlags
orisPatternLiteralPlaceholderType
which was introduced in #52836 .https://github.dev/microsoft/TypeScript/blob/97147915ab667a52e31ac743843786cbc9049559/src/compiler/checker.ts#L17967
The text was updated successfully, but these errors were encountered: