Skip to content

Commit ee29ef3

Browse files
authored
Add ts-auto-guard (#1319)
* Add ts-auto-guard package * Added ts-auto-guard case * Added support for ts-auto-guard * Fix ts-auto-guard place in readme list
1 parent 78c9f23 commit ee29ef3

File tree

11 files changed

+434
-32
lines changed

11 files changed

+434
-32
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ cases/spectypes/build
44
cases/ts-runtime-checks/build
55
cases/typia/build
66
cases/deepkit/build
7+
cases/ts-auto-guard/build
8+
cases/ts-auto-guard/src/index.guard.ts
79
jest.config.js

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,8 @@ cases/spectypes/build
160160
cases/ts-runtime-checks/build
161161

162162
# typia build artifacts
163-
cases/typia/build
163+
cases/typia/build
164+
165+
# ts-auto-guard build artifacts
166+
cases/ts-auto-guard/build
167+
cases/ts-auto-guard/src/index.guard.ts

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* [superstruct](https://github.com/ianstormtaylor/superstruct)
4343
* [suretype](https://github.com/grantila/suretype)
4444
* [toi](https://github.com/hf/toi)
45+
* [ts-auto-guard](https://github.com/rhys-vdw/ts-auto-guard)
4546
* [ts-interface-checker](https://github.com/gristlabs/ts-interface-checker)
4647
* [ts-json-validator](https://github.com/ostrowr/ts-json-validator)
4748
* [ts-runtime-checks](https://github.com/GoogleFeud/ts-runtime-checks)

cases/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const cases = [
4545
'zod',
4646
'deepkit',
4747
'effect-schema',
48+
'ts-auto-guard',
4849
] as const;
4950

5051
export type CaseName = (typeof cases)[number];

cases/ts-auto-guard/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { isLoose } from './build/index.guard';
2+
import { addCase } from '../../benchmarks';
3+
4+
addCase('ts-auto-guard', 'assertLoose', data => {
5+
if (!isLoose(data)) throw new Error('wrong type.');
6+
return true;
7+
});

cases/ts-auto-guard/src/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @see {isLoose} ts-auto-guard:type-guard */
2+
export interface Loose {
3+
number: number;
4+
negNumber: number;
5+
maxNumber: number;
6+
string: string;
7+
longString: string;
8+
boolean: boolean;
9+
deeplyNested: {
10+
foo: string;
11+
num: number;
12+
bool: boolean;
13+
};
14+
}

cases/ts-auto-guard/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "build",
6+
"strict": true,
7+
"strictNullChecks": true,
8+
},
9+
"include": ["src/index.ts", "src/index.guard.ts"]
10+
}
11+

index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ async function main() {
4141
stdio: 'inherit',
4242
});
4343
}
44+
if (c === 'ts-auto-guard') {
45+
childProcess.execSync('npm run compile:ts-auto-guard', {
46+
stdio: 'inherit',
47+
});
48+
}
4449

4550
const cmd = [...process.argv.slice(0, 2), 'run-internal', c];
4651

0 commit comments

Comments
 (0)