Skip to content

Commit d9dbe30

Browse files
committed
refactor(types): migrate from tsd to tstyche
1 parent bccb149 commit d9dbe30

2 files changed

Lines changed: 38 additions & 33 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint:fix": "eslint --fix",
3737
"test": "npm run test:unit && npm run test:typescript",
3838
"test:unit": "c8 --100 node --test",
39-
"test:typescript": "tsd"
39+
"test:typescript": "tstyche"
4040
},
4141
"dependencies": {
4242
"fastify-plugin": "^5.0.0"
@@ -48,7 +48,7 @@
4848
"fastify": "^5.0.0",
4949
"fp-ts": "^2.11.2",
5050
"neostandard": "^0.13.0",
51-
"tsd": "^0.33.0"
51+
"tstyche": "^7.0.0"
5252
},
5353
"homepage": "https://github.com/fastify/fastify-funky",
5454
"funding": [
@@ -89,4 +89,4 @@
8989
"publishConfig": {
9090
"access": "public"
9191
}
92-
}
92+
}
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fastify, { FastifyInstance, FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'
22
import { either, task, taskEither } from 'fp-ts'
3-
import { expectType, expectAssignable } from 'tsd'
4-
3+
import { expect } from 'tstyche'
54
import fastifyFunkyDefault, { fastifyFunky as fastifyFunkyNamed } from '..'
65
import * as fastifyFunkyStar from '..'
7-
import fastifyFunkyCjsImport = require('..')
6+
87
const fastifyFunkyCjs = require('./')
8+
import fastifyFunkyCjsImport = require('..')
99

1010
const app: FastifyInstance = fastify()
1111
app.register(fastifyFunkyNamed)
@@ -16,13 +16,12 @@ app.register(fastifyFunkyCjsImport.fastifyFunky)
1616
app.register(fastifyFunkyStar.default)
1717
app.register(fastifyFunkyStar.fastifyFunky)
1818

19-
expectType<FastifyPluginCallback>(fastifyFunkyNamed)
20-
expectType<FastifyPluginCallback>(fastifyFunkyDefault)
21-
expectType<FastifyPluginCallback>(fastifyFunkyCjsImport.default)
22-
expectType<FastifyPluginCallback>(fastifyFunkyCjsImport.fastifyFunky)
23-
expectType<FastifyPluginCallback>(fastifyFunkyStar.default)
24-
expectType<FastifyPluginCallback>(fastifyFunkyStar.fastifyFunky)
25-
expectType<any>(fastifyFunkyCjs)
19+
expect(fastifyFunkyNamed).type.toBe<FastifyPluginCallback>()
20+
expect(fastifyFunkyDefault).type.toBe<FastifyPluginCallback>()
21+
expect(fastifyFunkyCjsImport.default).type.toBe<FastifyPluginCallback>()
22+
expect(fastifyFunkyCjsImport.fastifyFunky).type.toBe<FastifyPluginCallback>()
23+
expect(fastifyFunkyStar.default).type.toBe<FastifyPluginCallback>()
24+
expect(fastifyFunkyStar.fastifyFunky).type.toBe<FastifyPluginCallback>()
2625

2726
app.register(fastifyFunkyDefault)
2827
// this gives a type error:
@@ -31,58 +30,64 @@ app.get('/', (_req: FastifyRequest, _reply: FastifyReply) => {
3130
})
3231

3332
app.get('/func', (req, reply) => {
34-
expectAssignable<FastifyRequest>(req)
35-
expectAssignable<FastifyReply>(reply)
33+
expect(req).type.toBeAssignableTo<FastifyRequest>()
34+
expect(reply).type.toBeAssignableTo<FastifyReply>()
3635
return () => {
3736
return { right: { id: 1 } }
3837
}
3938
})
4039

4140
app.get('/func', (req, reply) => {
42-
expectAssignable<FastifyRequest>(req)
43-
expectAssignable<FastifyReply>(reply)
41+
expect(req).type.toBeAssignableTo<FastifyRequest>()
42+
expect(reply).type.toBeAssignableTo<FastifyReply>()
4443
return Promise.resolve({})
4544
})
4645

4746
app.get('/func', (req, reply) => {
48-
expectAssignable<FastifyRequest>(req)
49-
expectAssignable<FastifyReply>(reply)
47+
expect(req).type.toBeAssignableTo<FastifyRequest>()
48+
expect(reply).type.toBeAssignableTo<FastifyReply>()
5049
reply.status(200).send({})
5150
})
5251

5352
// this is allowed
5453
app.get('/', (req, reply) => {
55-
expectAssignable<FastifyRequest>(req)
56-
expectAssignable<FastifyReply>(reply)
54+
expect(req).type.toBeAssignableTo<FastifyRequest>()
55+
expect(reply).type.toBeAssignableTo<FastifyReply>()
5756
return { right: { id: 1 } }
5857
})
58+
5959
app.get('/', (req, reply) => {
60-
expectAssignable<FastifyRequest>(req)
61-
expectAssignable<FastifyReply>(reply)
60+
expect(req).type.toBeAssignableTo<FastifyRequest>()
61+
expect(reply).type.toBeAssignableTo<FastifyReply>()
6262
return { left: new Error('error') }
6363
})
64+
6465
app.get('/', (req, reply) => {
65-
expectAssignable<FastifyRequest>(req)
66-
expectAssignable<FastifyReply>(reply)
66+
expect(req).type.toBeAssignableTo<FastifyRequest>()
67+
expect(reply).type.toBeAssignableTo<FastifyReply>()
6768
return taskEither.fromEither(either.left(new Error('Invalid state')))
6869
})
70+
6971
app.get('/', (req, reply) => {
70-
expectAssignable<FastifyRequest>(req)
71-
expectAssignable<FastifyReply>(reply)
72+
expect(req).type.toBeAssignableTo<FastifyRequest>()
73+
expect(reply).type.toBeAssignableTo<FastifyReply>()
7274
return taskEither.fromTask(task.of(Promise.resolve({})))
7375
})
76+
7477
app.get('/', (req, reply) => {
75-
expectAssignable<FastifyRequest>(req)
76-
expectAssignable<FastifyReply>(reply)
78+
expect(req).type.toBeAssignableTo<FastifyRequest>()
79+
expect(reply).type.toBeAssignableTo<FastifyReply>()
7780
return either.of(Promise.resolve({}))
7881
})
82+
7983
app.get('/', (req, reply) => {
80-
expectAssignable<FastifyRequest>(req)
81-
expectAssignable<FastifyReply>(reply)
84+
expect(req).type.toBeAssignableTo<FastifyRequest>()
85+
expect(reply).type.toBeAssignableTo<FastifyReply>()
8286
return task.of(Promise.resolve({}))
8387
})
88+
8489
app.get('/', (req, reply) => {
85-
expectAssignable<FastifyRequest>(req)
86-
expectAssignable<FastifyReply>(reply)
90+
expect(req).type.toBeAssignableTo<FastifyRequest>()
91+
expect(reply).type.toBeAssignableTo<FastifyReply>()
8792
return taskEither.of(Promise.resolve({}))
8893
})

0 commit comments

Comments
 (0)