Skip to content

Commit

Permalink
feat(types): 新增 IsEmptyArray
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jan 25, 2021
1 parent c056fd9 commit 7d3bdbd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/types/IsEmptyArray.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expectType } from '../dev'
import { IsEmptyArray } from './IsEmptyArray'

describe('IsEmptyArray', () => {
test('不是空数组', () => {
expectType<IsEmptyArray<number>, false>()
expectType<IsEmptyArray<boolean>, false>()
expectType<IsEmptyArray<string>, false>()
expectType<IsEmptyArray<RegExp>, false>()
expectType<IsEmptyArray<undefined>, false>()
expectType<IsEmptyArray<null>, false>()
expectType<IsEmptyArray<unknown>, false>()
expectType<IsEmptyArray<{}>, false>()
})

test('是空数组', () => {
expectType<IsEmptyArray<[]>, true>()
})
})
17 changes: 17 additions & 0 deletions src/types/IsEmptyArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NonEmptyArray } from './NonEmptyArray'

/**
* 判断 `T` 是否是空数组。
*
* @public
* @example
* ```typescript
* type X = IsEmptyArray<[]>
* // => true
* ```
*/
export type IsEmptyArray<T> = T extends any[]
? T extends NonEmptyArray<any>
? false
: true
: false
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export * from './Defined'
export * from './DotPath'
export * from './FirstParameter'
export * from './IsAny'
export * from './IsEmptyArray'
export * from './IsEmptyObject'
export * from './IsNever'
export * from './NonEmptyArray'
Expand Down

0 comments on commit 7d3bdbd

Please sign in to comment.