我遇到了这个奇怪的案例。我声明了一个条件类型。对于相同的extends约束,类型别名满足它,而结构相同的接口则不满足。
我很失落,为什么不同?检查操场。
interface Constraint {
[key: string]: string | number | boolean
}
type ATypeAlias = {
str: string
num: number
bool: boolean
}
interface SameInterface {
str: string
num: number
bool: boolean
}
type expectToBeTrue = ATypeAlias extends Constraint ? true : false
// Wat???
type butWhyAmIFalse = SameInterface extends Constraint ? true : false
Run Code Online (Sandbox Code Playgroud) typescript ×1