Microsoft/TypeScript
GitHub ã§èŠãConstraints of nested conditional types applied to constrained type variables are incorrect
Open
#59,868 opened on 2024幎9æ5æ¥
BugDomain: Conditional TypesHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
constraints conditional types type variables nested
ð Version & Regression Information
- This is the behavior in every version I tried
⯠Playground Link
ð» Code
type IsMatchingStringOneLevel<T extends string> = T extends `a${string}`
? true
: false;
function f2<S extends string>(x: IsMatchingStringOneLevel<S>) {
let t: true = x; // Error
let f: false = x; // Error
}
type IsMatchingStringTwoLevels<T extends string> = T extends `a${string}`
? T extends `${string}z`
? true
: false
: false;
function f3<S extends string>(x: IsMatchingStringTwoLevels<S>) {
let t: true = x; // Error
let f: false = x; // Ok but should be an error
}
ð Actual behavior
It doesn't error on the fourth assignment
ð Expected behavior
It should error
Additional information about the issue
This is just a variant of what was fixed for one-level conditionals in https://github.com/microsoft/TypeScript/pull/56004