From a36eb39ac07b41b5b392c101a8fbcfddfb2c6806 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Fri, 1 May 2026 09:06:50 +0200 Subject: [PATCH 1/3] refactor(types): migrate from tsd to tstyche --- package.json | 9 +-- types/index.d.ts | 35 +++++--- types/{index.test-d.ts => index.tst.ts} | 102 ++++++++++-------------- 3 files changed, 67 insertions(+), 79 deletions(-) rename types/{index.test-d.ts => index.tst.ts} (70%) diff --git a/package.json b/package.json index 29067a4..2729191 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint": "eslint", "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", - "test:typescript": "tsd", + "test:typescript": "tstyche", "test:unit": "borp -C --check-coverage --lines 100", "example": "node example/server.js", "example:benchmark": "node example/server-benchmark.js" @@ -78,12 +78,9 @@ "neostandard": "^0.12.0", "pino": "^10.0.0", "proxyquire": "^2.1.3", - "tsd": "^0.33.0" - }, - "tsd": { - "directory": "test/types" + "tstyche": "^7.0.0" }, "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 63874cb..c31d9ba 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -82,18 +82,23 @@ declare namespace fastifyStatic { type Root = string | string[] | URL | URL[] - type RootOptions = { - serve: true; - root: Root; - } | { - serve?: false; - root?: Root; - } + type RootOptions = + | { + serve: true; + root: Root; + } + | { + serve?: false; + root?: Root; + } + | { + serve?: boolean; + root?: Root; + } - export type FastifyStaticOptions = - SendOptions - & RootOptions - & { + export type FastifyStaticOptions = SendOptions & + RootOptions & + Omit & { // Added by this plugin prefix?: string; prefixAvoidTrailingSlash?: boolean; @@ -104,7 +109,11 @@ declare namespace fastifyStatic { wildcard?: boolean; globIgnore?: string[]; list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat; - allowedPath?: (pathName: string, root: string, request: FastifyRequest) => boolean; + allowedPath?: ( + pathName: string, + root: string, + request: FastifyRequest + ) => boolean; /** * @description * Opt-in to looking for pre-compressed files @@ -123,7 +132,7 @@ declare namespace fastifyStatic { lastModified?: boolean; maxAge?: string | number; constraints?: RouteOptions['constraints']; - logLevel?: RouteOptions['logLevel']; + logLevel?: NonNullable; } export const fastifyStatic: FastifyStaticPlugin diff --git a/types/index.test-d.ts b/types/index.tst.ts similarity index 70% rename from types/index.test-d.ts rename to types/index.tst.ts index afe4ce4..d165d29 100644 --- a/types/index.test-d.ts +++ b/types/index.tst.ts @@ -1,10 +1,10 @@ -import fastify, { FastifyInstance, FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify' -import { Server } from 'node:http' -import { Stats } from 'node:fs' -import { expectAssignable, expectError, expectType } from 'tsd' +import fastify, { type FastifyInstance, type FastifyPluginAsync, type FastifyRequest, type FastifyReply } from 'fastify' +import { type Server } from 'node:http' +import { type Stats } from 'node:fs' +import { expect } from 'tstyche' import * as fastifyStaticStar from '..' import fastifyStatic, { - FastifyStaticOptions, + type FastifyStaticOptions, fastifyStatic as fastifyStaticNamed } from '..' @@ -21,15 +21,13 @@ app.register(fastifyStaticCjsImport.fastifyStatic, { root: __dirname }) app.register(fastifyStaticStar.default, { root: __dirname }) app.register(fastifyStaticStar.fastifyStatic, { root: __dirname }) -expectType>(fastifyStatic) -expectType>(fastifyStaticNamed) -expectType>(fastifyStaticCjsImport.default) -expectType>(fastifyStaticCjsImport.fastifyStatic) -expectType>(fastifyStaticStar.default) -expectType>( - fastifyStaticStar.fastifyStatic -) -expectType(fastifyStaticCjs) +expect(fastifyStatic).type.toBe>() +expect(fastifyStaticNamed).type.toBe>() +expect(fastifyStaticCjsImport.default).type.toBe>() +expect(fastifyStaticCjsImport.fastifyStatic).type.toBe>() +expect(fastifyStaticStar.default).type.toBe>() +expect(fastifyStaticStar.fastifyStatic).type.toBe>() +expect(fastifyStaticCjs).type.toBe() const appWithImplicitHttp = fastify() const options: FastifyStaticOptions = { @@ -53,14 +51,14 @@ const options: FastifyStaticOptions = { globIgnore: ['**/*.private'], list: false, setHeaders: (res, path, stat) => { - expectType(res.filename) - expectType(res.statusCode) - expectType>(res.getHeader('X-Test')) + expect(res.filename).type.toBe() + expect(res.statusCode).type.toBe() + expect(res.getHeader('X-Test')).type.toBe>() res.setHeader('X-Test', 'string') - expectType(path) + expect(path).type.toBe() - expectType(stat) + expect(stat).type.toBe() }, preCompressed: false, allowedPath: (_pathName: string, _root: string, _request: FastifyRequest) => { @@ -73,65 +71,49 @@ const options: FastifyStaticOptions = { logLevel: 'warn' } -expectError({ - root: '', - wildcard: '**/**' -}) - -expectAssignable({ +expect({ root: '', list: { - format: 'json' + format: 'json' as const } -}) +}).type.toBeAssignableTo() -expectAssignable({ +expect({ root: '', list: { - format: 'json', + format: 'json' as const, render: () => '' } -}) +}).type.toBeAssignableTo() -expectAssignable({ +expect({ root: '', list: { - format: 'html', + format: 'html' as const, render: () => '' } -}) - -expectError({ - root: '', - list: { - format: 'html' - } -}) +}).type.toBeAssignableTo() -expectAssignable({ +expect({ root: [''] -}) +}).type.toBeAssignableTo() -expectAssignable({ - root: new URL('') -}) +expect({ + root: new URL('file://') +}).type.toBeAssignableTo() -expectAssignable({ - root: [new URL('')] -}) +expect({ + root: [new URL('file://')] +}).type.toBeAssignableTo() -expectError({ - serve: true -}) - -expectAssignable({ - serve: true, +expect({ + serve: true as const, root: '' -}) +}).type.toBeAssignableTo() -expectAssignable({ - serve: false -}) +expect({ + serve: false as const +}).type.toBeAssignableTo() appWithImplicitHttp .register(fastifyStatic, options) @@ -218,7 +200,7 @@ noIndexApp }) }) -options.root = new URL('') +options.root = new URL('file://') const URLRootApp = fastify() URLRootApp.register(fastifyStatic, options) @@ -229,7 +211,7 @@ URLRootApp.register(fastifyStatic, options) }) const defaultIndexApp = fastify() -options.index = 'index.html' +options.index = 'index.html' as const defaultIndexApp .register(fastifyStatic, options) From f82fed6c70b9d9311beab647264b7e948fc120b6 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Fri, 1 May 2026 15:51:52 +0200 Subject: [PATCH 2/3] refactor(types): updated --- types/index.tst.ts | 88 +++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/types/index.tst.ts b/types/index.tst.ts index d165d29..d5d08c7 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -71,49 +71,55 @@ const options: FastifyStaticOptions = { logLevel: 'warn' } -expect({ - root: '', - list: { - format: 'json' as const - } -}).type.toBeAssignableTo() +expect() + .type.toBeAssignableFrom({ + root: '', + list: { + format: 'json' as const + } + }) -expect({ - root: '', - list: { - format: 'json' as const, - render: () => '' - } -}).type.toBeAssignableTo() +expect() + .type.toBeAssignableFrom({ + root: '', + list: { + format: 'json' as const, + render: () => '' + } + }) -expect({ - root: '', - list: { - format: 'html' as const, - render: () => '' - } -}).type.toBeAssignableTo() - -expect({ - root: [''] -}).type.toBeAssignableTo() - -expect({ - root: new URL('file://') -}).type.toBeAssignableTo() - -expect({ - root: [new URL('file://')] -}).type.toBeAssignableTo() - -expect({ - serve: true as const, - root: '' -}).type.toBeAssignableTo() - -expect({ - serve: false as const -}).type.toBeAssignableTo() +expect() + .type.toBeAssignableFrom({ + root: '', + list: { + format: 'html' as const, + render: () => '' + } + }) + +expect() + .type.toBeAssignableFrom({ + root: [''] + }) + +expect() + .type.toBeAssignableFrom({ + root: new URL('file://') + }) + +expect() + .type.toBeAssignableFrom({ root: [new URL('file://')] }) + +expect() + .type.toBeAssignableFrom({ + serve: true as const, + root: '' + }) + +expect() + .type.toBeAssignableFrom({ + serve: false as const + }) appWithImplicitHttp .register(fastifyStatic, options) From f68526fd63351951c304d559f9afc46d40ad9c98 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 13 May 2026 12:27:41 +0200 Subject: [PATCH 3/3] chore: updated --- types/index.d.ts | 4 ---- types/index.tst.ts | 7 +++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index c31d9ba..d01b9d3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -91,10 +91,6 @@ declare namespace fastifyStatic { serve?: false; root?: Root; } - | { - serve?: boolean; - root?: Root; - } export type FastifyStaticOptions = SendOptions & RootOptions & diff --git a/types/index.tst.ts b/types/index.tst.ts index d5d08c7..b47b285 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -116,10 +116,9 @@ expect() root: '' }) -expect() - .type.toBeAssignableFrom({ - serve: false as const - }) +expect().type.not.toBeAssignableFrom({ + serve: true as const, +}) appWithImplicitHttp .register(fastifyStatic, options)