savior
v1.0.0
Published
Excessively simple type reflection.
Downloads
62
Maintainers
Readme
Installation
Savior can be installed using npm i -D savior
.
It requires the library ts-patch, installed using npm i -D ts-patch
.
You will also, of course, need to install the typescript
package.
Then, users must include the line "transform": "savior"
in the compilerOptions
section of their tsconfig.json
.
An example tsconfig.json
would look like this:
{
"compilerOptions": {
"lib": ["ESNext", "dom"],
"plugins": [
{
"transform": "savior"
}
]
}
}
Files can then be compiled using npx tspc
.
Usage
Savior adds only two functions, reflectType
and reflectTypeLit
.
reflectType
takes a type and places it directly into the AST, as follows:
type Empty = [];
const array = reflectType<Empty>;
array.push("Hello, world!");
// Prints: ["Hello, world!"]
console.log(array);
reflectTypeLit
takes a type and converts it into a string, as follows:
type Union = number | string;
let str = reflectTypeLit<Union>;
str += " | Other";
// Prints: number | string | Other
console.log(str);