请问,Exclude是什么?
我在代码中有看到:
type HP = 'left' | 'center' | 'right'
type VP = 'top' | 'center' | 'bottom'
type ToastProps = {
position:
| Exclude<`${HP}-${VP}`, 'center-center'>
| 'center'
}
请问:Exclude<> 是属于哪里的功能?是TypeScript的?
请问,Exclude是什么?
我在代码中有看到:
type HP = 'left' | 'center' | 'right'
type VP = 'top' | 'center' | 'bottom'
type ToastProps = {
position:
| Exclude<`${HP}-${VP}`, 'center-center'>
| 'center'
}
请问:Exclude<> 是属于哪里的功能?是TypeScript的?
13 回答13k 阅读
8 回答2.8k 阅读
2 回答5.2k 阅读✓ 已解决
5 回答1.4k 阅读
3 回答2.3k 阅读✓ 已解决
3 回答1k 阅读✓ 已解决
5 回答1.7k 阅读✓ 已解决
是的,
Exclude
是 TypeScript 自带的内容,属于类型工具。若是在 VSCode 中按住 Window 键后点击Exclude
,即可观察到对应的实现。与其类似的,还有
Pick
、Extract
、Omit
,这些属于高级应用,所以一般的教程没有写(说实话我也还怎么在实战中用过)。放一个开源项目,其实挺有名的了,在其中刷刷题,可以解锁很多 TypeScript 的新姿势。