-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Milestone
Description
Bug Report
🔎 Search Terms
lowercase, uppercase, intrinsic, conditional type
🕗 Version & Regression Information
- This changed between versions 5.0.4 and 5.1.0-beta.
- 5.2.2 and nightly still have the same problem.
- I also reviewed the FAQ for entries about lowercase, uppercase, intrinsic and conditional types.
⏯ Playground Link
💻 Code
type A<S> = Lowercase<S&string> extends "foo" ? 1 : 0
// ^? type A<S> = 0
type B<S> = Lowercase<S&string> extends `f${string}` ? 1 : 0
// ^? type B<S> = 0
let x1: A<"foo"> = 1 // error
let x2: B<"foo"> = 1 // error
🙁 Actual behavior
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 .