小编hua*_*lin的帖子

为什么任何扩展 X ?A : B 给 A | 打字稿中的B?

type TestAny = any extends 'a' ? 1 : 2 // => 1 | 2  why??? how to understand?
type TestUnknown = unknown extends 'a' ? 1 : 2 // => 2
type TestStringA = 'a' extends 'a' ? 1 : 2 // => 1

type SomeUnion = 'a' | 'b'
type UnionDistribute<T> = T extends 'a' ? 1 : 2
type t0 = UnionDistribute<SomeUnion>  // => 1 | 2  // any work like an union
Run Code Online (Sandbox Code Playgroud)

为什么any extends 'a' …

typescript

7
推荐指数
1
解决办法
90
查看次数

标签 统计

typescript ×1