diff --git a/.eslintignore b/.eslintignore index b5617cdb9..479cf4cc3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,5 @@ cases/typia/build cases/deepkit/build cases/ts-auto-guard/build cases/ts-auto-guard/src/index.guard.ts +cases/type-predicate-generator/build +cases/type-predicate-generator/src/index_guards.ts diff --git a/.gitignore b/.gitignore index b6d395225..1968c1ef2 100644 --- a/.gitignore +++ b/.gitignore @@ -166,5 +166,9 @@ cases/typia/build cases/ts-auto-guard/build cases/ts-auto-guard/src/index.guard.ts +# type-predicate-generator build artifacts +cases/type-predicate-generator/build +cases/type-predicate-generator/src/index_guards.ts + # Bun binary lock file makes mergin harder. Using text lock file instead. bun.lockb diff --git a/README.md b/README.md index 6c0b2ef4a..8b0862196 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ * [ts-runtime-checks](https://github.com/GoogleFeud/ts-runtime-checks) * [tson](https://github.com/skarab42/tson) * [ts-utils](https://github.com/ai-labs-team/ts-utils) +* [type-predicate-generator](https://github.com/peter-leonov/typescript-predicate-generator) * [typia](https://github.com/samchon/typia) * [@typeofweb/schema](https://github.com/typeofweb/schema) * [unknownutil](https://github.com/lambdalisue/deno-unknownutil) diff --git a/cases/index.ts b/cases/index.ts index b0878e07d..eb46cfc9c 100644 --- a/cases/index.ts +++ b/cases/index.ts @@ -51,6 +51,7 @@ export const cases = [ 'deepkit', 'effect-schema', 'ts-auto-guard', + 'type-predicate-generator', 'jet-schema', ] as const; diff --git a/cases/type-predicate-generator/index.ts b/cases/type-predicate-generator/index.ts new file mode 100644 index 000000000..f803fb5a2 --- /dev/null +++ b/cases/type-predicate-generator/index.ts @@ -0,0 +1,7 @@ +import { isLoose } from './src/index_guards'; +import { addCase } from '../../benchmarks'; + +addCase('type-predicate-generator', 'assertLoose', data => { + if (!isLoose(data)) throw new Error('wrong type.'); + return true; +}); diff --git a/cases/type-predicate-generator/src/index.ts b/cases/type-predicate-generator/src/index.ts new file mode 100644 index 000000000..bc5f50177 --- /dev/null +++ b/cases/type-predicate-generator/src/index.ts @@ -0,0 +1,13 @@ +export type Loose = { + number: number; + negNumber: number; + maxNumber: number; + string: string; + longString: string; + boolean: boolean; + deeplyNested: { + foo: string; + num: number; + bool: boolean; + }; +}; diff --git a/cases/type-predicate-generator/tsconfig.json b/cases/type-predicate-generator/tsconfig.json new file mode 100644 index 000000000..c6917813c --- /dev/null +++ b/cases/type-predicate-generator/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "build", + "strict": true, + "strictNullChecks": true + }, + "include": ["src/index.ts", "src/index_guards.ts"] +} diff --git a/download-packages-popularity.ts b/download-packages-popularity.ts index 71de17ad6..f3c51c7b3 100644 --- a/download-packages-popularity.ts +++ b/download-packages-popularity.ts @@ -210,6 +210,10 @@ export const packages = [ name: 'ts-auto-guard', packageName: 'ts-auto-guard', }, + { + name: 'type-predicate-generator', + packageName: 'type-predicate-generator', + }, ] as const; interface BodyWeeklyDownloads { diff --git a/index.ts b/index.ts index 19602d056..0c7e75d3b 100644 --- a/index.ts +++ b/index.ts @@ -46,6 +46,11 @@ async function main() { stdio: 'inherit', }); } + if (c === 'type-predicate-generator') { + childProcess.execSync('npm run compile:type-predicate-generator', { + stdio: 'inherit', + }); + } const cmd = [...process.argv.slice(0, 2), 'run-internal', c]; diff --git a/package-lock.json b/package-lock.json index 7650474c8..0d31a56c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,6 +69,7 @@ "ts-json-validator": "0.7.1", "ts-node": "10.9.2", "ts-runtime-checks": "0.6.3", + "type-predicate-generator": "0.1.11", "typescript": "5.6.3", "typia": "7.5.1", "undici": "7.2.1", @@ -9572,6 +9573,34 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/type-predicate-generator": { + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/type-predicate-generator/-/type-predicate-generator-0.1.11.tgz", + "integrity": "sha512-gXQOmmLUvQMKyIp7buXTS20EsnNwNvNgO5EyW03PIrvbFlIj/vTs0I+ZM+wiwRytv2d7lI4MdeH/hXWuBmPh4A==", + "license": "MIT", + "dependencies": { + "typescript": ">=5.7.0 <5.8.0" + }, + "bin": { + "type-predicate-generator": "dist/cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/type-predicate-generator/node_modules/typescript": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/typescript": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", @@ -17120,6 +17149,21 @@ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true }, + "type-predicate-generator": { + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/type-predicate-generator/-/type-predicate-generator-0.1.11.tgz", + "integrity": "sha512-gXQOmmLUvQMKyIp7buXTS20EsnNwNvNgO5EyW03PIrvbFlIj/vTs0I+ZM+wiwRytv2d7lI4MdeH/hXWuBmPh4A==", + "requires": { + "typescript": ">=5.7.0 <5.8.0" + }, + "dependencies": { + "typescript": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==" + } + } + }, "typescript": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", diff --git a/package.json b/package.json index 1400f01ca..480c7c2f2 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "lint": "gts check", "lint:fix": "gts fix", "start": "ts-node index.ts", - "test:build": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typebox && npm run compile:typia && npm run compile:deepkit && npm run compile:ts-auto-guard && tsc --noEmit", - "test": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typebox && npm run compile:typia && npm run compile:deepkit && npm run compile:ts-auto-guard && vitest run", + "test:build": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typebox && npm run compile:typia && npm run compile:deepkit && npm run compile:ts-auto-guard && npm run compile:type-predicate-generator && tsc --noEmit", + "test": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typebox && npm run compile:typia && npm run compile:deepkit && npm run compile:ts-auto-guard && npm run compile:type-predicate-generator && vitest run", "docs:serve": "serve docs", "docs:watch": "tsc --project tsconfig.docs.json --watch --preserveWatchOutput & serve docs", "docs:build": "tsc --project tsconfig.docs.json", @@ -23,6 +23,7 @@ "compile:typebox": "ts-node cases/typebox/index.ts cases/typebox/build", "compile:typia": "rimraf cases/typia/build && tsc -p cases/typia/tsconfig.json", "compile:ts-auto-guard": "rimraf cases/ts-auto-guard/build && ts-auto-guard --project cases/ts-auto-guard/tsconfig.json && tsc -p cases/ts-auto-guard/tsconfig.json", + "compile:type-predicate-generator": "rimraf cases/type-predicate-generator/src/index_guards.ts && (cd cases/type-predicate-generator/src && type-predicate-generator ./index.ts) && tsc -p cases/type-predicate-generator/tsconfig.json", "prepare": "ts-patch install", "download-packages-popularity": "ts-node download-packages-popularity.ts" }, @@ -87,6 +88,7 @@ "ts-json-validator": "0.7.1", "ts-node": "10.9.2", "ts-runtime-checks": "0.6.3", + "type-predicate-generator": "0.1.11", "typescript": "5.6.3", "typia": "7.5.1", "undici": "7.2.1", diff --git a/test/benchmarks.test.ts b/test/benchmarks.test.ts index bb332a589..1fe2db8ec 100644 --- a/test/benchmarks.test.ts +++ b/test/benchmarks.test.ts @@ -55,6 +55,7 @@ import '../cases/zod'; import '../cases/deepkit'; import '../cases/effect-schema'; import '../cases/ts-auto-guard'; +import '../cases/type-predicate-generator'; import '../cases/tiny-schema-validator'; import '../cases/jet-schema';