From e79ee20d27654f8560c9eec1a0c3cbb49470f270 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Sat, 25 Apr 2026 19:23:32 +0200 Subject: [PATCH 1/3] refactor(types): migrate from tsd to tstyche --- package.json | 9 +++++-- types/{index.test-d.ts => index.tst.ts} | 34 ++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) rename types/{index.test-d.ts => index.tst.ts} (83%) diff --git a/package.json b/package.json index cbe9b014..b9c25957 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "benchmark": "node --expose-gc ./benchmark/bench-cmp-lib.js", "lint": "eslint", "lint:fix": "eslint --fix", - "test:typescript": "tsd", + "test:typescript": "tstyche", "test:unit": "c8 node --test", "test": "npm run test:unit && npm run test:typescript" }, @@ -72,7 +72,7 @@ "neostandard": "^0.13.0", "simple-git": "^3.30.0", "tinybench": "^6.0.0", - "tsd": "^0.33.0", + "tstyche": "^7.1.0", "typebox": "^1.0.81", "typescript": "~6.0.2", "webpack": "^5.104.1" @@ -85,5 +85,10 @@ "json-schema-ref-resolver": "^3.0.0", "rfdc": "^1.2.0" }, + "tstyche": { + "testFileMatch": [ + "types/*.tst.ts" + ] + }, "runkitExampleFilename": "./examples/example.js" } diff --git a/types/index.test-d.ts b/types/index.tst.ts similarity index 83% rename from types/index.test-d.ts rename to types/index.tst.ts index 50da4201..9adb2834 100644 --- a/types/index.test-d.ts +++ b/types/index.tst.ts @@ -1,7 +1,7 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683 import Ajv from 'ajv' import build, { restore, Schema, validLargeArrayMechanisms } from '..' -import { expectError, expectType } from 'tsd' +import { expect } from 'tstyche' // Number schemas build({ @@ -26,9 +26,10 @@ build({ build({ type: 'number' }, { rounding: 'trunc' }) -expectError(build({ + +expect(build).type.not.toBeCallableWith({ type: 'number' -}, { rounding: 'invalid' })) +}, { rounding: 'invalid' }) // String schema build({ @@ -153,7 +154,6 @@ build({ })({ something: 'a string', somethingElse: 42 }) // String schema with format - build({ type: 'string', format: 'date-time' @@ -181,7 +181,6 @@ str = build({ type: 'number' }, { mode: 'standalone' }) */ - const debugCompiled = build({ title: 'default string', type: 'object', @@ -191,11 +190,12 @@ const debugCompiled = build({ } } }, { mode: 'debug' }) -expectType>(build.restore(debugCompiled)) -expectType>(restore(debugCompiled)) -expectType(build.validLargeArrayMechanisms) -expectType(validLargeArrayMechanisms) +expect(build.restore(debugCompiled)).type.toBe>() +expect(restore(debugCompiled)).type.toBe>() + +expect(build.validLargeArrayMechanisms).type.toBe() +expect(validLargeArrayMechanisms).type.toBe() /** * Schema inference @@ -211,10 +211,11 @@ const stringify3 = build({ type: 'object', properties: { a: { type: 'string' } }, }) + stringify3({ id: '123' }) stringify3({ a: 123, id: '123' }) -expectError(stringify3({ anotherOne: 'bar' })) -expectError(stringify3({ a: 'bar' })) +expect(stringify3).type.not.toBeCallableWith({ anotherOne: 'bar' }) +expect(stringify3).type.not.toBeCallableWith({ a: 'bar' }) // Without inference const stringify4 = build({ @@ -231,29 +232,28 @@ const stringify5 = build({ type: 'string', }) stringify5('foo') -expectError(stringify5({ id: '123' })) +expect(stringify5).type.not.toBeCallableWith({ id: '123' }) // Without inference - null type const stringify6 = build({ type: 'null', }) stringify6(null) -expectError(stringify6('a string')) +expect(stringify6).type.not.toBeCallableWith('a string') // Without inference - boolean type const stringify7 = build({ type: 'boolean', }) stringify7(true) -expectError(stringify7('a string')) +expect(stringify7).type.not.toBeCallableWith('a string') // largeArrayMechanism - build({}, { largeArrayMechanism: 'json-stringify' }) build({}, { largeArrayMechanism: 'default' }) -expectError(build({} as Schema, { largeArrayMechanism: 'invalid' })) +expect(build).type.not.toBeCallableWith({} as Schema, { largeArrayMechanism: 'invalid' }) build({}, { largeArraySize: 2000 }) build({}, { largeArraySize: '2e4' }) build({}, { largeArraySize: 2n }) -expectError(build({} as Schema, { largeArraySize: ['asdf'] })) +expect(build).type.not.toBeCallableWith({} as Schema, { largeArraySize: ['asdf'] }) From 0b1cd767854d46befccf48085ef199db7cbaece8 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Sun, 26 Apr 2026 11:22:42 +0200 Subject: [PATCH 2/3] chore: update package.json --- package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/package.json b/package.json index b9c25957..286e64b9 100644 --- a/package.json +++ b/package.json @@ -85,10 +85,5 @@ "json-schema-ref-resolver": "^3.0.0", "rfdc": "^1.2.0" }, - "tstyche": { - "testFileMatch": [ - "types/*.tst.ts" - ] - }, "runkitExampleFilename": "./examples/example.js" } From 4ead84294e46f0745f94ab5de8706ddbff757c02 Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Sun, 26 Apr 2026 11:26:24 +0200 Subject: [PATCH 3/3] chore: update index.tst.ts Co-authored-by: Tom Mrazauskas Signed-off-by: Antonio Tripodi --- types/index.tst.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/index.tst.ts b/types/index.tst.ts index 9adb2834..f2d7ff2c 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -191,8 +191,8 @@ const debugCompiled = build({ } }, { mode: 'debug' }) -expect(build.restore(debugCompiled)).type.toBe>() -expect(restore(debugCompiled)).type.toBe>() +expect(build.restore(debugCompiled)).type.toBe(build({} as Schema)) +expect(restore(debugCompiled)).type.toBe(build({} as Schema)) expect(build.validLargeArrayMechanisms).type.toBe() expect(validLargeArrayMechanisms).type.toBe()