【发布时间】:2021-03-16 17:33:20
【问题描述】:
我遇到了这个奇怪的案例。我声明了一个条件类型。对于相同的extends 约束,类型别名满足它,而结构相同的接口则不满足。
我很迷茫,为什么会有不同?检查playground。
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
【问题讨论】:
标签: typescript