Home

Awesome

TypeScript Schema Library

Overview

A reflective type model for TypeScript applications. There are two primary models:

A high level over-view of the modules in this library are:

Usage

Install:

npm install typescript-schema

Basic Usage:

import * as s from 'typescript-schema'

let rawModules:s.Map<s.Module>

// Given a raw model, filter its contents to only contain types relevant to and referenced by some module
let filteredModules = s.filterRawModules(['moduleA'], rawModules)

// Given a raw model, convert to a resolved one:
let resolvedModules = s.convertRawModules(rawModules)

// Give a raw model, create a nice text format
let str = s.stringify(rawModules)
// And parse it back into a raw model
rawModules = s.parse(str)

let someInterfaceConstructor:s.InterfaceConstructor
let someTypeForT:s.Type
// Given a type constructor (e.g. interface A<T>), create a type
s.closeInterface(someInterfaceConstructor, [someTypeForT])

// Visit the elements in a model
s.modulesVisitor(resolveModules, {
  onModule: function(module){
    return <s.ModuleVisitor> {
      onClassConstructor: function(cc) {
        // etc
      }
    }
  }
})

// Get the unique id for an element
let id = s.interfaceConstructorToString(someInterfaceConstructor)

let decorator:s.Decorator

// For some expression (e.g. from a decorator)
let pureValue = s.expressionToLiteral(decorator.parameters[0])

let someOtherInterfaceConstructor

// Compare two entities
let isEqual = someInterfaceConstructor.equals(someOtherInterfaceConstructor)