Denoguard .Deno based type guard code generator.
Deno based type guard code generator.
Type guard code generation tool written for DenoJs.
This tool is written using DenoJs.
To run the tool invoke it with the
test-interfaces.ts file has some example input source code to use during development for testing. For example to run the tool on this file:
deno run --allow-read --unstable main.ts -f test-interfaces.ts
To test the tool run with the
deno test --unstable
This tool parses source files for interface definitions using the same parser that Deno uses (SWC). It then generates Typescript type guards for these interfaces. The type guards are named
is<interface name> (The
<interface name> will have it's first letter capitalized).
Interface type guards are constructed by combining smaller pre-defined and tested type guards, which we will call sub type guards. Each of these sub type guards test one property of an unknown type. The code generator determines what properties of an interface need to be tested and combines the appropriate sub type guards together to satisfy an interface's requirements.
These sub type guards reside in the
guards.ts file. When Denoguard itself is built this
guard.ts file is parsed (using the same SWC Typescript parser) and each sub type guard's abstract syntax tree is slightly transformed. The transformation ensures the sub type guard functions are ready for code generation purposes by removing
export keywords from before function definitions. Then in preparation for Denoguard code generation the resulting sub type guard's Typescript source code strings are saved to the
guards_generated.ts file, which will included in the final Denoguard bundle distribution.
This process ensures that type guards can be tested and are reliable.
Source Code: https://github.com/Screeos/denoguard
Deno is released, it’s time to find out if it can prove a worthy competition for Node.js. What is Deno? Why Deno can be considered an alternative to Node? The main differences between Deno and Node. Write a simple Deno app.