Skip to content

Not

自 1.1.0 起

布尔类型的逻辑非运算。

签名

typescript
type Not<B extends boolean> = B extends true ? false : true

参数

参数描述
B要取反的布尔类型

示例

基本用法

typescript
import type { Not } from 'uni-types'

type A = Not<true>   // false
type B = Not<false>  // true

条件类型

typescript
import type { Not, IsAny } from 'uni-types'

type IsDefined<T> = Not<IsAny<T>>

type A = IsDefined<string>  // true
type B = IsDefined<any>     // false

相关

  • If - 条件类型
  • And - 逻辑与
  • Or - 逻辑或

基于 MIT 许可发布