Skip to content

Commit 9fd4d42

Browse files
committed
refactor(types): migrate from tsd to tstyche
1 parent 9237ec8 commit 9fd4d42

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint:fix": "eslint --fix",
1111
"test": "npm run test:unit && npm run test:types",
1212
"test:unit": "c8 --100 node --test",
13-
"test:types": "tsd"
13+
"test:types": "tstyche"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -65,13 +65,18 @@
6565
"eslint": "^9.17.0",
6666
"fastify": "^5.0.0",
6767
"neostandard": "^0.13.0",
68-
"tsd": "^0.33.0"
68+
"tstyche": "^7.0.0"
6969
},
7070
"dependencies": {
7171
"@fastify/error": "^4.0.0",
7272
"fastify-plugin": "^5.0.0"
7373
},
74+
"tstyche": {
75+
"testFileMatch": [
76+
"types/*.tst.ts"
77+
]
78+
},
7479
"publishConfig": {
7580
"access": "public"
7681
}
77-
}
82+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectType, expectAssignable } from 'tsd'
1+
import { expect } from 'tstyche'
22
import fastify, {
33
FastifyRequest,
44
FastifyReply,
@@ -14,36 +14,36 @@ const app = fastify()
1414
// validation ok
1515
app.register(fastifyBasicAuth, {
1616
validate: async function validatePromise (username, password, req, reply) {
17-
expectType<string>(username)
18-
expectType<string>(password)
19-
expectType<FastifyRequest>(req)
20-
expectType<FastifyReply>(reply)
21-
expectType<FastifyInstance>(this)
17+
expect(username).type.toBe<string>()
18+
expect(password).type.toBe<string>()
19+
expect(req).type.toBe<FastifyRequest>()
20+
expect(reply).type.toBe<FastifyReply>()
21+
expect(this).type.toBe<FastifyInstance>()
2222
},
2323
header: 'x-forwarded-authorization'
2424
})
2525

2626
// validation failure
2727
app.register(fastifyBasicAuth, {
2828
validate: async function validatePromise (username, password, req, reply) {
29-
expectType<string>(username)
30-
expectType<string>(password)
31-
expectType<FastifyRequest>(req)
32-
expectType<FastifyReply>(reply)
33-
expectType<FastifyInstance>(this)
29+
expect(username).type.toBe<string>()
30+
expect(password).type.toBe<string>()
31+
expect(req).type.toBe<FastifyRequest>()
32+
expect(reply).type.toBe<FastifyReply>()
33+
expect(this).type.toBe<FastifyInstance>()
3434
return new Error('unauthorized')
3535
},
3636
header: 'x-forwarded-authorization'
3737
})
3838

3939
app.register(fastifyBasicAuth, {
4040
validate: function validateCallback (username, password, req, reply, done) {
41-
expectType<string>(username)
42-
expectType<string>(password)
43-
expectType<FastifyRequest>(req)
44-
expectType<FastifyReply>(reply)
45-
expectAssignable<(err?: Error) => void>(done)
46-
expectType<FastifyInstance>(this)
41+
expect(username).type.toBe<string>()
42+
expect(password).type.toBe<string>()
43+
expect(req).type.toBe<FastifyRequest>()
44+
expect(reply).type.toBe<FastifyReply>()
45+
expect(done).type.toBeAssignableTo<(err?: Error) => void>()
46+
expect(this).type.toBe<FastifyInstance>()
4747
}
4848
})
4949

@@ -98,6 +98,6 @@ app.register(fastifyBasicAuth, {
9898
utf8: undefined
9999
})
100100

101-
expectAssignable<onRequestHookHandler>(app.basicAuth)
102-
expectAssignable<preValidationHookHandler>(app.basicAuth)
103-
expectAssignable<preHandlerHookHandler>(app.basicAuth)
101+
expect(app.basicAuth).type.toBeAssignableTo<onRequestHookHandler>()
102+
expect(app.basicAuth).type.toBeAssignableTo<preValidationHookHandler>()
103+
expect(app.basicAuth).type.toBeAssignableTo<preHandlerHookHandler>()

0 commit comments

Comments
 (0)