Static Type Assert
Asserting type with help of TypeScript compiler
Requirements
- Node.js ≥ 8.9.0
- TypeScript ≥ 3.0.0
Usage
1. Create TypeScript files
Example: pass.ts
// Comma-separated parametersassert'hello', 'world'assert123, 456, 789 // Curry function callsassert'abc'123'def'456 // Combineassert'a', 0'c', 'd'1, 2
Example: fail.ts
assert'abc' // Expected Error: Argument of type '"abc"' is not assignable to type 'number'
2. Use TypeScript compiler to check types
tsc --noEmit
Example: pass.ts
tsc --noEmit pass.ts # Expects to pass (no errors)
Example: fail.ts
tsc --noEmit fail.ts # Expects errors