Skip to content

Commit

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

describe('IsEmptyObject', () => {
test('不是空对象', () => {
expectType<IsEmptyObject<number>, false>()
expectType<IsEmptyObject<boolean>, false>()
expectType<IsEmptyObject<string>, false>()
expectType<IsEmptyObject<RegExp>, false>()
expectType<IsEmptyObject<undefined>, false>()
expectType<IsEmptyObject<null>, false>()
expectType<IsEmptyObject<unknown>, false>()
expectType<IsEmptyObject<any[]>, false>()
})

test('是空对象', () => {
expectType<IsEmptyObject<{}>, true>()
})
})
13 changes: 13 additions & 0 deletions src/types/IsEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IsNever } from './IsNever'

/**
* 判断 `T` 是否是空对象。
*
* @public
* @example
* ```typescript
* type X = IsEmptyObject<{}>
* // => true
* ```
*/
export type IsEmptyObject<T> = T extends Object ? IsNever<keyof T> : 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 './IsEmptyObject'
export * from './IsNever'
export * from './NonEmptyArray'
export * from './OneOrMore'
Expand Down

0 comments on commit c056fd9

Please sign in to comment.