[Typia] executable demo site of 20,000x faster validator (serializer)
Tags: typescript, javascript, opensource, react
Published: 2024-03-18 14:16:46

## Outline

> https://typia.io/playground

I've published an executable playground website of `typia` to demonstrate how `typia` is easier than other runtime validation (serialization) libraries, and describe what the AoT (Ahead of Compilation) is for TypeScript users.

Just visit the [playground website](https://typia.io/playground), and click the "execute" button. Then you may understand what I mean.

[![Playground website of typia](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9u788k87ly3azm3a1z8.png)](https://typia.io/playground)

```typescript
// RUNTIME VALIDATORS
export function is<T>(input: unknown): input is T; // returns boolean
export function assert<T>(input: unknown): T; // throws TypeGuardError
export function assertGuard<T>(input: unknown): asserts input is T;
export function validate<T>(input: unknown): IValidation<T>; // detailed
 
// JSON FUNCTIONS
export namespace json {
  export function application<T>(): IJsonApplication; // JSON schema
  export function assertParse<T>(input: string): T; // type safe parser
  export function assertStringify<T>(input: T): string; // safe and faster
}
 
// PROTOCOL BUFFER
export namespace protobuf {
  export function message<T>(): string; // Protocol Buffer message
  export function assertDecode<T>(buffer: Uint8Array): T; // safe decoder
  export function assertEncode<T>(input: T): Uint8Array; // safe encoder
}
 
// RANDOM GENERATOR
export function random<T>(g?: Partial<IRandomGenerator>): T;
```



## `typia`

> Story of `typia`.
>
> https://github.com/samchon/typia

`typia` is a transformer library supporting below features:

- Super-fast Runtime Validators
- Enhanced JSON functions
- Protocol Buffer encoder and decoder
- Random data generator

Also, `typia` does not require any extra schema definition like `ajv` or `class-validator`, but needs only the **pure TypeScript type**. Furthermore, its runtime validation is maximum **20,000x faster** than `class-validator`, and JSON serialization is **200x** faster than `class-transformer`.

All the secrets of `typia` (ability to understand the pure TypeScript type, and super-fast performance) are based on the AoT (Ahead of Time) compilation. `typia` analyzes your TypeScript codes and types in the compliation level, and writes optimal validation and serialization code for each type.

[![Benchmark](https://raw.githubusercontent.com/samchon/typia/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/is.svg)](https://github.com/samchon/typia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz)





## Demonstration

> I made it for demonstration.

By the way, is my above explanation easy to understand? 

I'd written some articles introducing `typia` on here `dev.to`, but more than half of the readers only understood that as "Wow, `typia` is super fast." I'd hoped to emphasize the "AoT compilation" concept and "easiness" as well as "super-fast", but I'd failed to appeal them cleary.

This is the reason why I've published the playground website, even including the TypeScript compiler, bundler and exector which can run on the web browser.

Visit the https://typia.io/playground/ website, and write any TpeScript source code what you want. Then, you may understand how `typia` generates optimal validation and serialization code for your pure TypeScript type through the AoT compilation.

If you click the "execute" button of the right side, playground website will compile your TypeScript code, and run it on your browser. So that you can realize that `typia` is not a fake library, but the real convenient one.

[![Playground website of typia](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9u788k87ly3azm3a1z8.png)](https://typia.io/playground)




## Stability

> Stable than any others.

I've shown that `typia` is super-fast and even easier to use through above chapters. 

By the way, from the perspective of a runtime validation and serialization library, there is one thing that is much more important than ease or performance, and that is **stability**. No matter how fast and easy a library is, if it has poor stability and frequent bugs, it is a library of no value.

Furthermore, as `typia` guides users to utilize the pure TypeScript type, `typia` have to support every TypeScript types (In contrary, other libraries do not need to do it because they need extra schema definition). In such reason, I've concentrated on the test program development, because I had to.

Now, LOC of `typia` test program is about 250K. If includes the generated files, it overs 5M LOC. With long time efforts of test program developments, I can say with confident, "`typia` is the most stable library".

  - Line of Codes
    - main program: 34,516
    - test program: 246,229
    - test program (generated): 5,013,547

Components               | `typia` | `TypeBox` | `ajv` | `io-ts` | `zod` | `C.V.`
-------------------------|--------|-----------|-------|---------|-------|------------------
**Easy to use**          | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ 
[Object (simple)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectSimple.ts)          | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
[Object (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectHierarchical.ts)    | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
[Object (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectRecursive.ts)       | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ | ✔
[Object (union, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
[Object (union, explicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionExplicit.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
[Object (additional tags)](https://github.com/samchon/typia/#comment-tags)        | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
[Object (template literal types)](https://github.com/samchon/typia/blob/master/test/src/structures/TemplateUnion.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌
[Object (dynamic properties)](https://github.com/samchon/typia/blob/master/test/src/structures/DynamicTemplate.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌
[Array (rest tuple)](https://github.com/samchon/typia/blob/master/test/src/structures/TupleRestAtomic.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
[Array (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayHierarchical.ts)     | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
[Array (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursive.ts)        | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
[Array (recursive, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionExplicit.ts) | ✔ | ✔ | ❌ | ✔ | ✔ | ❌
[Array (R+U, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionImplicit.ts)    | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
[Array (repeated)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedNullable.ts)    | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
[Array (repeated, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedUnionWithTuple.ts)    | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
[**Ultimate Union Type**](https://github.com/samchon/typia/blob/master/src/schemas/IJsonSchema.ts)  | ✅ | ❌ | ❌ | ❌ | ❌ | ❌