4.0.1 • Published 4 years ago

static-type-assert v4.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
4 years ago

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

import assert from 'static-type-assert'

// Comma-separated parameters
assert<string>('hello', 'world')
assert<number>(123, 456, 789)

// Curry function calls
assert<'abc' | 'def' | 123 | 456>('abc')(123)('def')(456)

// Combine
assert<string | number>('a', 0)('c', 'd')(1, 2)

Example: fail.ts

import assert from 'static-type-assert'
assert<number>('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

License

MIT © Hoàng Văn Khải

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago