Outline
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, and click the “execute” button. Then you may understand what I mean.
// 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
.
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.
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.
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
[fluentform id="8"]