我使用了TypeScript Deep Dive中描述的穷举检查 与不是联合类型的类型相比,联合类型的穷举检查的工作方式似乎不同。为什么??例如,在下面的代码中,请注意,只有当我们断言x.kind为never时,exhaustivenessCheck1才能工作(不会在不应该输入error时输入error)。然而,只有当我们断言x是never时,e
Fails type check, even though all the unioned functions accept string.编译器将notCallable的类型推断为((v: string) => string) | ((v: string | number) => string),它看起来很好,但不能被认为是可调用的:
无法调用类型缺少调用签名的表达式。类型'((v: string) =&