Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ts-auto-guard #1319

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ cases/spectypes/build
cases/ts-runtime-checks/build
cases/typia/build
cases/deepkit/build
cases/ts-auto-guard/build
cases/ts-auto-guard/src/index.guard.ts
jest.config.js
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,8 @@ cases/spectypes/build
cases/ts-runtime-checks/build

# typia build artifacts
cases/typia/build
cases/typia/build

# ts-auto-guard build artifacts
cases/ts-auto-guard/build
cases/ts-auto-guard/src/index.guard.ts
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [superstruct](https://github.com/ianstormtaylor/superstruct)
* [suretype](https://github.com/grantila/suretype)
* [toi](https://github.com/hf/toi)
* [ts-auto-guard](https://github.com/rhys-vdw/ts-auto-guard)
* [ts-interface-checker](https://github.com/gristlabs/ts-interface-checker)
* [ts-json-validator](https://github.com/ostrowr/ts-json-validator)
* [ts-runtime-checks](https://github.com/GoogleFeud/ts-runtime-checks)
Expand Down
1 change: 1 addition & 0 deletions cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const cases = [
'zod',
'deepkit',
'effect-schema',
'ts-auto-guard',
] as const;

export type CaseName = (typeof cases)[number];
Expand Down
7 changes: 7 additions & 0 deletions cases/ts-auto-guard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { isLoose } from './build/index.guard';
import { addCase } from '../../benchmarks';

addCase('ts-auto-guard', 'assertLoose', data => {
if (!isLoose(data)) throw new Error('wrong type.');
return true;
});
14 changes: 14 additions & 0 deletions cases/ts-auto-guard/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @see {isLoose} ts-auto-guard:type-guard */
export interface Loose {
number: number;
negNumber: number;
maxNumber: number;
string: string;
longString: string;
boolean: boolean;
deeplyNested: {
foo: string;
num: number;
bool: boolean;
};
}
11 changes: 11 additions & 0 deletions cases/ts-auto-guard/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "build",
"strict": true,
"strictNullChecks": true,
},
"include": ["src/index.ts", "src/index.guard.ts"]
}

5 changes: 5 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ async function main() {
stdio: 'inherit',
});
}
if (c === 'ts-auto-guard') {
childProcess.execSync('npm run compile:ts-auto-guard', {
stdio: 'inherit',
});
}

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

Expand Down
Loading