Skip to content

Commit

Permalink
Don't narrow generic on type specific assertions (#168)
Browse files Browse the repository at this point in the history
* Don't narrow generic on type specific assertions. Closes #167

* Allow specifying custom type using just 1 parameter
  • Loading branch information
kanongil authored Nov 20, 2021
1 parent 8f5dba6 commit 4d61ad1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export namespace thrownAt {
*
* @returns Assertion object.
*/
export function expect<T>(value: T, prefix?: string):
T extends string ? expect.StringAssertion<T> :
T extends number | bigint ? expect.NumberAssertion<T> :
T extends Promise<any> ? expect.PromiseAssertion<T> :
export function expect<T, TTest extends T = T>(value: T, prefix?: string):
TTest extends string ? expect.StringAssertion<T> :
TTest extends number | bigint ? expect.NumberAssertion<T> :
TTest extends Promise<any> ? expect.PromiseAssertion<T> :
expect.Assertion<T>;

declare namespace expect {
Expand Down
6 changes: 6 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ await expect.type<Promise<CustomError>>(Code.expect(typedRejection).to.reject(Cu
await expect.type<Promise<CustomError>>(Code.expect(typedRejection).rejects(CustomError, 'Oh no!'));

await expect.type<Promise<null>>(Code.expect(Promise.resolve(true)).to.not.reject());

function foo(): number | undefined {
return 123;
}

Code.expect(foo()).to.equal(123);

0 comments on commit 4d61ad1

Please sign in to comment.