Skip to content

Commit 70787cc

Browse files
authored
fix(types): Fix assert types, clarify that second param is required (#215)
1 parent 190d2a3 commit 70787cc

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

types/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ declare module 'fastify' {
2828
}
2929

3030
interface Assert {
31-
(condition: unknown, code?: number | string, message?: string): asserts condition;
32-
ok(condition: unknown, code?: number | string, message?: string): asserts condition;
33-
equal(a: unknown, b: unknown, code?: number | string, message?: string): void;
34-
notEqual(a: unknown, b: unknown, code?: number | string, message?: string): void;
35-
strictEqual<T>(a: unknown, b: T, code?: number | string, message?: string): asserts a is T;
36-
notStrictEqual(a: unknown, b: unknown, code?: number | string, message?: string): void;
37-
deepEqual(a: unknown, b: unknown, code?: number | string, message?: string): void;
38-
notDeepEqual(a: unknown, b: unknown, code?: number | string, message?: string): void;
31+
(condition: unknown, code: number, message?: string): asserts condition;
32+
ok(condition: unknown, code: number, message?: string): asserts condition;
33+
equal(a: unknown, b: unknown, code: number, message?: string): void;
34+
notEqual(a: unknown, b: unknown, code: number, message?: string): void;
35+
strictEqual<T>(a: unknown, b: T, code: number, message?: string): asserts a is T;
36+
notStrictEqual(a: unknown, b: unknown, code: number, message?: string): void;
37+
deepEqual(a: unknown, b: unknown, code: number, message?: string): void;
38+
notDeepEqual(a: unknown, b: unknown, code: number, message?: string): void;
3939
}
4040

4141
interface FastifyInstance {

types/index.test-d.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ app.get('/', async () => {
114114
})
115115

116116
app.get('/', async () => {
117-
expectType<void>(app.assert(1))
118-
expectType<void>(app.assert.ok(true))
119-
expectType<void>(app.assert.equal(1, 1))
120-
expectType<void>(app.assert.notEqual(1, 2))
121-
expectType<void>(app.assert.strictEqual(1, 1))
122-
expectType<void>(app.assert.notStrictEqual(1, 2))
123-
expectType<void>(app.assert.deepEqual({}, {}))
124-
expectType<void>(app.assert.notDeepEqual({}, { a: 1 }))
117+
expectError(app.assert(true))
118+
expectType<void>(app.assert(1, 400, 'Bad number'))
119+
expectType<void>(app.assert.ok(true, 400))
120+
expectType<void>(app.assert.equal(1, 1, 400))
121+
expectType<void>(app.assert.notEqual(1, 2, 400))
122+
expectType<void>(app.assert.strictEqual(1, 1, 400))
123+
expectType<void>(app.assert.notStrictEqual(1, 2, 400))
124+
expectType<void>(app.assert.deepEqual({}, {}, 400))
125+
expectType<void>(app.assert.notDeepEqual({}, { a: 1 }, 400))
125126
})
126127

127128
app.get('/', async () => {

0 commit comments

Comments
 (0)