为什么这两种类型的联合不在函数内部提供参数提示?
type Valish = (value: string) => boolean
type CurryValish = (...args: number[]) => Valish
const check = {
vin: (value) => true, // ✗ any, should be string
cin: (curry) => (value) => true, // ✗ any any, should ne number string
} satisfies {
[key: string]:
| Valish
| CurryValish
}
const checkValish = {
vin: (value) => true, // 🗸 string => boolean
} satisfies { [key: string]: Valish }
const checkCurry = {
cin: (curry) => (value) => true, // 🗸 number => string => boolean
} satisfies { [key: string]: CurryValish }
它似乎足够好地理解上下文以提供大量信息,甚至在CurryValish类型的内部也是如此.那么,当替换为有效类型时,它为什么不提供参数类型呢?
const x: Valish | CurryValish = (a) => "hi"
// Type 'string' is not assignable to type 'boolean | Valish'.(2322)
const y: Valish | CurryValish = (b) => (a) => "hi"
// Type '(a: any) => string' is not assignable to type 'boolean | Valish'.
// Type '(a: any) => string' is not assignable to type 'Valish'.
// Type 'string' is not assignable to type 'boolean'.