JSPM

misc-utils-of-mine-typescript

0.0.12
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q43960F
  • License MIT

TypeScript type helpers and related misc utilities

Package Exports

  • misc-utils-of-mine-typescript

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (misc-utils-of-mine-typescript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Utilities for dealing / defining types in TypeScript.

API

API

Examples:

Example with array

Check given array length

type Manager = 'John'|'Chris'|'Laura'
type Developer = 'Sebastian'|'Andrew'|'Gabriel'
type Name = Manager|Developer

interface Person<N extends Name> {
  name: N
  age?: number
}

// we want to check that developers in a team has exactly the number they declare at compile time
interface Team<DeveloperCount extends number> {
  manager: Person<Manager>
  developers: ArrayLiteral<Person<Developer>, DeveloperCount>
 }

 // strictly check that given developers length corresponds to team's declaration
declare function setDevelopers<DeveloperCount extends number>(team: Team<DeveloperCount>, developers: ArrayLiteral<Person<Developer>, DeveloperCount>):void

declare var team2: Team<2>
declare var team1: Team<1>

// OK:
setDevelopers(team2, [{name: 'Sebastian'}, {name: 'Andrew'}])
setDevelopers(team1, [{name: 'Sebastian'}])

// fail to compile:
setDevelopers(team2, []) 
setDevelopers(team1, [{name: 'Sebastian'}, {name: 'Andrew'}])