banner
SlhwSR

SlhwSR

热爱技术的一名全栈开发者
github
bilibili

ts泛型条件匹配

当有需求要求根据传入类型匹配对对应类型时,实现如下:

type Expample=string

type C<T>=T extends Example?string:boolean

const res:C<string | number>=true

const res2:C<string>="12321412"
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.