11import fastify , { FastifyInstance , FastifyPluginCallback , FastifyReply , FastifyRequest } from 'fastify'
22import { either , task , taskEither } from 'fp-ts'
3- import { expectType , expectAssignable } from 'tsd'
4-
3+ import { expect } from 'tstyche'
54import fastifyFunkyDefault , { fastifyFunky as fastifyFunkyNamed } from '..'
65import * as fastifyFunkyStar from '..'
7- import fastifyFunkyCjsImport = require ( '..' )
6+
87const fastifyFunkyCjs = require ( './' )
8+ import fastifyFunkyCjsImport = require( '..' )
99
1010const app : FastifyInstance = fastify ( )
1111app . register ( fastifyFunkyNamed )
@@ -16,13 +16,12 @@ app.register(fastifyFunkyCjsImport.fastifyFunky)
1616app . register ( fastifyFunkyStar . default )
1717app . 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
2726app . register ( fastifyFunkyDefault )
2827// this gives a type error:
@@ -31,58 +30,64 @@ app.get('/', (_req: FastifyRequest, _reply: FastifyReply) => {
3130} )
3231
3332app . 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
4140app . 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
4746app . 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
5453app . 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+
5959app . 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+
6465app . 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+
6971app . 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+
7477app . 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+
7983app . 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+
8489app . 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