I encountered a peculiar situation. I defined a conditional type where a type alias satisfies the extends
constraint, but an interface with identical structure does not.
I'm perplexed by this discrepancy. To see it in action, visit the 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
// Strange!
type butWhyAmIFalse = SameInterface extends Constraint ? true : false