-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters