Microsoft/TypeScript
在 GitHub 查看Constraints of nested conditional types applied to constrained type variables are incorrect
Open
#59,868 建立於 2024年9月5日
BugDomain: Conditional TypesHelp Wanted
倉庫指標
- Star
- (48,455 star)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 9 個 PR)
描述
🔎 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