Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A typescript transformer that automatically generates validation code from your types.
| Date | Stars |
|---|---|
| 2026-07-24 | 407 |
| 2026-07-25 | 407 |
| 2026-07-28 | 407 |
| 2026-07-30 | 407 |
| 2026-08-06 | 407 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# ts-runtime-checks
A typescript transformer which automatically generates validation code from your types. Think of it as a validation library like [ajv](https://ajv.js.org/guide/typescript.html) and [zod](https://zod.dev/), except it completely relies on the typescript compiler, and generates vanilla javascript code on demand. This comes with a lot of advantages:
- It's just types - no boilerplate or schemas needed.
- Only validate where you see fit.
- Code is generated during the transpilation phase, and can be easily optimized by V8.
- Powerful - built on top of typescript's type system, which is turing-complete.
Here are some examples you can try out in the [playground](https://googlefeud.github.io/ts-runtime-checks/):
**Asserting function parameters:**
```ts
// Special `Assert` type get detected and generates validation code
function greet(name: Assert<string>, age: Assert<number>): string {
return `Hello ${name}, you are ${age} years old!`;
}
// Transpiles to:
function greet(name, age) {
if (typeof name !== "string") throw new Error("Expected name to be a string");
if (typeof age !== "number") throw new Error("Expected age to be a number");
return `Hello ${name}, you are ${age} years old!`;
}
```
**Checking whether a value is of a certain type:**
```ts
interface User {
name: string;
age: Min<13>;
}
const maybeUser = {name: "GoogleFeud", age: "123"};
// `is` function transpiles to the validation code
const isUser = is<User>(maybeUser);
// Transpiles to:
const isUser = typeof maybeUser === "object" && maybeUser !== null && typeof maybeUser.name === "string" && typeof maybeUser.age === "number" && maybeUser.age > 13;
```
**Pattern Matching:**
```ts
type WithValue = {value: string};
// `createMatch` function creates a pattern-matching function
const extractString = createMatch<string>([
(value: string | number) => value.toString(),
({value}: WithValue) => value,
() => {
throw new Error("Could not extract string.");
}
]);
//Transpiles to:
const extractString = value_1 => {
if (typeof value_1 === "string") return value_1.toString();
else if (typeof value_1 === "number") return value_1.toString();
else if (typeof value_1 === "object" && value_1 !== null) {
if (typeof value_1.value === "string") {
let {value} = value_1;
return value;
}
}
throw new Error("Could not extract string.");
};
```
## Usage
```
npm i --save-dev ts-runtime-checks
```
<details>
<summary>Usage with ts-patch</summary>
```
npm i --save-dev ts-patch
```
and add the ts-runtime-checks transformer to your tsconfig.json:
```json
"compilerOptions": {
//... other options
"plugins": [
{ "transform": "ts-runtime-checks" }
]
}
```
Afterwards you can either use the `tspc` CLI command to transpile your typescript code.
</details>
<details>
<summary>Usage with ts-loader</summary>
```js
const TsRuntimeChecks = require("ts-runtime-checks").default;
options: {
getCustomTransformers: program => {
before: [TsRuntimeChecks(program)];
};
}
```
</details>
<details>
<summary>Usage with ts-node</summary>
To use transformers with ts-node, you'll have to change the compiler in the `tsconfig.json`:
```
npm i --save-dev ts-patch
```
```json
"ts-node": {
"compiler": "ts-patch"
},
"compilerOptions": {
"plugins": [
{ "transform": "ts-runtime-checks" }
]
}
```
</details>
## `ts-runtime-checks` in depth
### Markers
Markers are typescript type aliases which are detected by the transformer. These types don't represent actual values, but they tell the transformer what code to generate. Think of them as functions!
By far the most important marker is `Assert<T>`, which tells the transpiler to validate the type `T`. There are also `utility` markers which can be used inside an `Assert` marker to customize the validation in some way or to add extra checks. Here's the list of all utilitExcerpt of 24,027 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:3a8cc076063f6c31, topic:transformer