tinspector
TypeScript type inspector
![Coverage Status](https://coveralls.io/repos/github/ktutnik/tinspector/badge.svg?branch=master)
Description
tinspector is a type inspector used to extract metadata from JavaScript (TypeScript generated) Function, Class, Module
Simple Reflect
import reflect from "tinspector"
class MyAwesomeClass {
constructor(id:number, name:string){}
myAwesomeMethod(stringPar:string){}
}
const metadata = reflect(MyAwesomeClass)
Reflect With Type Information
TypeScript provided design type information by using decorator.
To get a proper type information on function parameter and its return type
you can use noop decorator (decorator that does nothing).
- To get type information of constructor parameter decorate the class
- To get type information of method/property decorate the method/property itself
import reflect, { decorate } from "tinspector"
@decorate({})
class MyAwesomeClass {
constructor(id:number, name:string){}
@decorate({})
myAwesomeMethod(stringPar:string): number { return 1 }
}
const metadata = reflect(MyAwesomeClass)
Reflect With Decorator Information
Use predefined decorator decorate
, decorateClass
, decorateMethod
, decorateProperty
, decorateParameter
to add
decorator informaton that understand by reflect
import reflect, { decorateMethod } from "tinspector"
class MyAwesomeClass {
@decorateMethod({ type: "Cache", cache: '60s' })
myAwesomeMethod(stringPar:string){}
}
const metadata = reflect(MyAwesomeClass)
Reflect Parameter Properties
TypeScript parameter properties information erased after transpile, so you need to tell tinspector
that you have parameter properties by decorate class using @reflect.parameterProperties()
import reflect from "tinspector"
@reflect.parameterProperties()
class MyAwesomeClass {
constructor(public id:number, public name:string){}
}
const metadata = reflect(MyAwesomeClass)
@reflect.parameterProperties()
assume that all of the class parameter is parameter property,
to exclude parameter from transformed into property use @reflect.ignore()
@reflect.parameterProperties()
class MyAwesomeClass {
constructor(public id:number, public name:string, @reflect.ignore() nonProperty:string){}
}
Reflect With Inheritance
tinspector will traverse through base classes property to get proper meta data.
class BaseClass {
@decorate({})
myAwesomeMethod(stringPar:string): number { return 1 }
}
class MyAwesomeClass {
@decorate({})
myAwesomeMethod(stringPar:string): number { return 1 }
}
Ignore Member From Metadata Generated
Reflect Array Element Type
Reflect Generic Type