Skip to content

Commit 6e7b5ab

Browse files
committed
feat: strongly typed typeof hints
1 parent d0cccd3 commit 6e7b5ab

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/chai/interface/assert.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,25 @@ export interface AssertInterface {
7676
isFinite(val: number, msg?: string): void;
7777
isBoolean(val: unknown, msg?: string): asserts val is boolean;
7878
isNotBoolean(val: unknown, msg?: string): void;
79+
80+
// typeof
81+
typeOf(val: unknown, type: 'undefined'): asserts val is undefined;
82+
typeOf(val: unknown, type: 'null'): asserts val is null;
83+
typeOf(val: unknown, type: 'map'): asserts val is Map<unknown, unknown>;
84+
typeOf(val: unknown, type: 'set'): asserts val is Set<unknown>;
85+
typeOf(val: unknown, type: 'promise'): asserts val is Promise<unknown>;
86+
typeOf(val: unknown, type: 'string'): asserts val is string;
87+
typeOf(val: unknown, type: 'number'): asserts val is number;
88+
typeOf(val: unknown, type: 'array'): asserts val is Array<unknown>;
89+
typeOf(val: unknown, type: 'boolean'): asserts val is boolean;
7990
typeOf(val: unknown, type: string, msg?: string): void;
8091
notTypeOf(val: unknown, type: string, msg?: string): void;
81-
instanceOf<T>(val: T, type: Constructor<T>, msg?: string): void;
92+
93+
// instanceof
94+
instanceOf<T extends Constructor<unknown>>(val: unknown, type: T, msg?: string): asserts val is InstanceType<T>;
8295
notInstanceOf(val: object, type: Constructor<unknown>, msg?: string): void;
96+
97+
// includes
8398
include(expr: CollectionLike<unknown> | string | object, inc: unknown, msg?: string): void;
8499
notInclude(expr: CollectionLike<unknown> | string | object, inc: unknown, msg?: string): void;
85100
deepInclude(expr: CollectionLike<unknown> | string | object, inc: unknown, msg?: string): void;
@@ -92,8 +107,12 @@ export interface AssertInterface {
92107
notOwnInclude(expr: object, inc: unknown, msg?: string): void;
93108
deepOwnInclude(expr: object, inc: unknown, msg?: string): void;
94109
notDeepOwnInclude(expr: object, inc: unknown, msg?: string): void;
110+
111+
// match
95112
match(expr: string, re: RegExp, msg?: string): void;
96113
notMatch(expr: string, re: RegExp, msg?: string): void;
114+
115+
// properties
97116
property<T extends object, TKey extends PropertyKey>(
98117
obj: T,
99118
prop: TKey,
@@ -127,6 +146,7 @@ export interface AssertInterface {
127146
notDeepNestedPropertyVal(obj: unknown, prop: string, val: unknown, msg?: string): void;
128147
lengthOf(expr: LengthLike, len: number, msg?: string): void;
129148

149+
// keys
130150
hasAnyKeys(
131151
obj: Set<unknown> | Map<unknown, unknown>,
132152
keys: unknown[],
@@ -282,6 +302,8 @@ export interface AssertInterface {
282302
operator<T>(val: T, operator: string, val2: T, msg?: string): void;
283303
closeTo(actual: number, expected: number, delta: number, msg?: string): void;
284304
approximately(actual: number, expected: number, delta: number, msg?: string): void;
305+
306+
// members
285307
sameMembers<T>(set1: T[], set2: T[], msg?: string): void;
286308
notSameMembers<T>(set1: T[], set2: T[], msg?: string): void;
287309
sameDeepMembers<T>(set1: T[], set2: T[], msg?: string): void;
@@ -298,6 +320,7 @@ export interface AssertInterface {
298320
notIncludeOrderedMembers<T>(superset: T[], subset: T[], msg?: string): void;
299321
includeDeepOrderedMembers<T>(superset: T[], subset: T[], msg?: string): void;
300322
notIncludeDeepOrderedMembers<T>(superset: T[], subset: T[], msg?: string): void;
323+
301324
oneOf<T extends string | unknown[]>(inList: T, list: T[], msg?: string): void;
302325

303326
changes<T>(

0 commit comments

Comments
 (0)