1.0.0-beta.7 • Published 7 years ago
magic-type v1.0.0-beta.7
Installation
- With Yarn
yarn global add magic-type- With NPM
npm install -g magic-typeYou could also use Magic Type locally as well.
Usage
Let's take the following code as an example.
// typings/api.ts
export type MyAPIRequest = {
time: number;
input: string;
};Compile TypeScript definitions
Usage: magictype [options]
Options:
-V, --version output the version number
-i --inputFile <file> The entrypoint of files to be compiled
-o --outputDir <dir> The output directory of compiled files
-c --cjs Transpile modules to CommonJS (Otherwise it will output ES modules)
-h, --help output usage informationUse magic types at runtime
import { MyAPIRequest } from "./api";
// Use Magic Types as normal TypeScript types
type MyType = {
key: MyAPIRequest;
};
// Use Magic Type at Runtime
// Check if user input matches MyAPIRequest
function checkMyInput(input: any) {
return MyAPIRequest.validate(input);
}
// Format user input to match MyAPIRequest
function formatMyInput(input: any) {
return MyAPIRequest.format(input);
}
// Generate a mock MyAPIRequest data
function getMockData() {
return MyAPIRequest.deriveLiteral([]).mock();
}Developer Experience with TypeScript's type guard

Runtime Screenshot:

Unsupported Syntax
Please be noted there's no warnings against unsupported syntax yet (And Magic Type may crash as well). Please kindly check by yourself.
extendskeyword ininterfacedeclaration will be ignored.- Union (
A | B) and intersection(A & B) on index signatures are not supported. - Functions
inferkeywordReturnType<T>andInstanceType<T>are not supported due to unsupportedinferkeyword and functions.
License
Magic Type is MIT licensed
1.0.0-beta.7
7 years ago
1.0.0-beta.6
7 years ago
1.0.0-beta.5
7 years ago
1.0.0-beta.4
7 years ago
1.0.0-beta.3
7 years ago
1.0.0-beta.2
7 years ago
1.0.0-beta.1
7 years ago
0.0.0
7 years ago
