Cryrivers / Magic Type
Licence: mit
🎩 Use Your TypeScript definitions at runtime. Powered by Manta Style.
Stars: ✭ 53
Programming Languages
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Magic Type
Topshell
TopShell - a purely functional, reactive scripting language
Stars: ✭ 422 (+696.23%)
Mutual labels: type-safety
Pcf Nominal
A formalisation of PCF in Agda using naive nominal binding
Stars: ✭ 5 (-90.57%)
Mutual labels: type-safety
Scalacss
Super type-safe CSS for Scala and Scala.JS.
Stars: ✭ 293 (+452.83%)
Mutual labels: type-safety
Structopt
Parse command line arguments by defining a struct
Stars: ✭ 323 (+509.43%)
Mutual labels: type-safety
Gentype
Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType.
Stars: ✭ 683 (+1188.68%)
Mutual labels: type-safety
nest-typed-config
Intuitive, type-safe configuration module for Nest framework ✨
Stars: ✭ 47 (-11.32%)
Mutual labels: type-safety
Phpcs Type Sniff
PHP CodeSniffer sniff to enforce PHP 7 types and documentation of array variables
Stars: ✭ 35 (-33.96%)
Mutual labels: type-safety
Graphaello
A Tool for Writing Declarative, Type-Safe and Data-Driven Applications in SwiftUI using GraphQL
Stars: ✭ 355 (+569.81%)
Mutual labels: type-safety
Flow Runtime
A runtime type system for JavaScript with full Flow compatibility.
Stars: ✭ 813 (+1433.96%)
Mutual labels: type-safety
Mammoth
A type-safe Postgres query builder for TypeScript.
Stars: ✭ 305 (+475.47%)
Mutual labels: type-safety
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (+490.57%)
Mutual labels: type-safety
Nexus Plugin Prisma
A plugin for Nexus that integrates Prisma
Stars: ✭ 728 (+1273.58%)
Mutual labels: type-safety
Type safe
Zero overhead utilities for preventing bugs at compile time
Stars: ✭ 866 (+1533.96%)
Mutual labels: type-safety
Swift Nonempty
🎁 A compile-time guarantee that a collection contains a value.
Stars: ✭ 585 (+1003.77%)
Mutual labels: type-safety
Typewiz
Automatically discover and add missing types in your TypeScript code
Stars: ✭ 1,026 (+1835.85%)
Mutual labels: type-safety
Zion
A statically-typed strictly-evaluated garbage-collected readable programming language.
Stars: ✭ 33 (-37.74%)
Mutual labels: type-safety
Swift Tagged
🏷 A wrapper type for safer, expressive code.
Stars: ✭ 801 (+1411.32%)
Mutual labels: type-safety
Magic Type
🎩 Use Your TypeScript definitions at runtime. Powered by Manta Style.
Installation
- With Yarn
yarn global add magic-type
- With NPM
npm install -g magic-type
You 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 information
Use 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
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.
-
extends
keyword ininterface
declaration will be ignored. - Union (
A | B
) and intersection(A & B
) on index signatures are not supported. - Functions
-
infer
keyword -
ReturnType<T>
andInstanceType<T>
are not supported due to unsupportedinfer
keyword and functions.
License
Magic Type is MIT licensed
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].