Skip to content

Commit 4d61ad1

Browse files
authoredNov 20, 2021
Don't narrow generic on type specific assertions (#168)
* Don't narrow generic on type specific assertions. Closes #167 * Allow specifying custom type using just 1 parameter
1 parent 8f5dba6 commit 4d61ad1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎lib/index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ export namespace thrownAt {
9292
*
9393
* @returns Assertion object.
9494
*/
95-
export function expect<T>(value: T, prefix?: string):
96-
T extends string ? expect.StringAssertion<T> :
97-
T extends number | bigint ? expect.NumberAssertion<T> :
98-
T extends Promise<any> ? expect.PromiseAssertion<T> :
95+
export function expect<T, TTest extends T = T>(value: T, prefix?: string):
96+
TTest extends string ? expect.StringAssertion<T> :
97+
TTest extends number | bigint ? expect.NumberAssertion<T> :
98+
TTest extends Promise<any> ? expect.PromiseAssertion<T> :
9999
expect.Assertion<T>;
100100

101101
declare namespace expect {

‎test/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,9 @@ await expect.type<Promise<CustomError>>(Code.expect(typedRejection).to.reject(Cu
200200
await expect.type<Promise<CustomError>>(Code.expect(typedRejection).rejects(CustomError, 'Oh no!'));
201201

202202
await expect.type<Promise<null>>(Code.expect(Promise.resolve(true)).to.not.reject());
203+
204+
function foo(): number | undefined {
205+
return 123;
206+
}
207+
208+
Code.expect(foo()).to.equal(123);

0 commit comments

Comments
 (0)
Please sign in to comment.