Helpers for working with typescript's reflection.
$ npm install @slicky/reflection
Annotation definition:
import {makeClassDecorator} from '@slicky/reflection';
class NamedClassDefinition
{
constructor(name: string) { ... }
}
let NamedClass = makeClassDecorator(NamedClassDefinition);
Usage:
import {getAnnotations, findAnnotation} from '@slicky/reflection';
@NamedClass('Test')
class TestClass { ... }
// get all annotations on class:
getAnnotations(TestClass);
// finding annotation for class:
findAnnotation(TestClass, NamedClassDefinition);
##Properties metadata
Properties metadata can be used also for methods and accessors.
Metadata definition:
import {makePropertyDecorator} from '@slicky/reflection';
class NamedPropertyDefinition
{
constructor(name: string) { ... }
}
let NamedProperty = makePropertyDecorator(NamedPropertyDefinition);
Usage:
import {getPropertiesMetadata, getPropertyMetadata, findPropertyMetadata} from '@slicky/reflection';
class TestClass
{
@NamedProperty('test')
prop;
}
// get all properties on class:
getPropertiesMetadata(TestClass);
// get all metadata for property "prop":
getPropertyMetadata(TestClass, 'prop');
// finding metadata for property "prop":
findPropertyMetadata(TestClass, NamedPropertyDefinition, 'prop');
Metadata definition:
import {makeParameterDecorator} from '@slicky/reflection';
class NamedParameterDefinition
{
constructor(name: string) { ... }
}
let NamedParameter = makeParameterDecorator(NamedParameterDefinition);
Usage:
import {getParametersMetadata, findParameterMetadata} from '@slicky/reflection';
class TestClass
{
constructor(@NamedParameter('param') arg) { ... }
method(arg1, @NamedParameter('param2') arg2) { ... }
}
// get all parameters in constructor:
getParametersMetadata(TestClass);
// get all parameters in method "method":
getParametersMetadata(TestClass, 'method');
// finding metadata for first argument in constructor:
findParameterMetadata(TestClass, NamedParameterDefinition, 0);
// finding metadata for second argument in method "method":
findParameterMetadata(TestClass, NamedParameterDefinition, 1, 'method');