All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Method and function overloads,
Type.toString()
- returns string with kind, name and fullName of the type.
- Type.function replaced by Type.getSignatures();
- Type.isSymbol(): boolean;
- Type.getIndexes(): IndexInfo[];
- Class
Property
renamed toPropertyInfo
, - class
Constructor
renamed toConstructorInfo
, - class
Method
renamed toMethodInfo
, - property
index
removed fromPropertyInfo
- indexes are moved to separate collection - seeType.getIndexes()
, - changed way how properties and indexes are generated, which add support of the Record<>, Omit<> etc.
- Type.isGenericType(): boolean;
- Type.genericTypeDefinition: Type | undefined;
- Each "instance" of a generic type is unique type with same genericTypeDefinition.
Eg. lets have aninterface Ifce<T> {}
.getType<IFce<string>>()
if different type thangetType<IFce<number>>()
.
PropertygenericTypeDefinition
of both types returns the same typeIFce<T>
, which is the definition of the generic type. This type is generic type too. - Support of ES modules and the NodeNext option.
- Generic type forwarding.
function foo<X>()
{
bar<X>(); // forward the type
const type = getType<X>();
doSomethingWithTypeHere(type);
}
function bar<Y>()
{
baz<Y>(); // forward the type
}
function baz<Z>()
{
const type = getType<Z>();
}
class A
{
}
foo<A>();
- Fix of recursive ("lazy") types,
- small fixes and PRs.
- Ids of types are generated from ts.Type, not from ts.Symbol anymore.
Type.isPromise()
Type.isTuple()
- but it is not implemented by the transformer yet.
examples/di
,
- Enhanced generic types
- now it is possible to infer type from passed argument, no need to specify type argument, eg:
-
function getTypeName<T extends string | number>(arg: T): string { return getType<T>().name; } getTypeName("Lorem ipsum dolor sit amet"); // > "string"
-
- function/method argument can be
arg: T
,arg: T[]
or...args: T[]
. Other arguments eg.arg: T | boolean
are resolved toType.Unknown
. There is still room for improvement. BTW you can still get type of passed valuegetType(arg)
. - fixed issues with `arguments` and `Function.length.
- Fixed some troubles with generated metadata,
- small performance optimizations,
- modified way of getting types' ids,
- NOTE: git repository renamed to
tst-reflect
- Fixed issue throwing Error about calling
getType()
without generic argument from transpilation.
- New tests (#28) - coverage ~88 %.
- Changed way of handling types of runtime value.
Now there isSomeClass.prototype[REFLECTED_TYPE_ID] = ID of SomeClass's type;
generated for each class in the project (not just those decorated via@reflect
). It does not mean that metadata of those classes will be generated. Logic of generating type's metadata is still the same, usegetType<SomeClass>()
somewhere, apply@reflect
decorator or apply any other decorator tagged by@reflect
JSDoc tag.
This is preparation for include/exclude configuration (issue #29). - custom decorators tagged by
@reflect
JSDoc tag does not have to have generic parameter
Type.isAny()
Type.isAssignableTo()
- added support of Arrays; fixed issue with optional members
Type.toString()
- [BREAKING]
Type.ctor: Function | undefined
changed toType.getCtor(): Promise<Function | undefined>
Generated Promise is based on target module from tsconfig.
Generated code in case of ESM:import("...path...").ExportedMember
otherwise:Promise.resolve(require("...path...").ExportedMember)
.
Native types (String, Number, Object, etc..) are always generated as eg.:Promise.resolve(Object)
- Fixed
Method.optional
- [BREAKING]
Type.union
changed toType.isUnion()
- [BREAKING]
Type.intersection
changed toType.isIntersection()
- Fixed of issue #23 - access to ctor of not exported class
getType(val: any)
it is possible to get type of runtime value,
-
const someValue: unknown = new Animal(); getType(someValue); // > Type<Animal>
This works mainly with classes. Before #29 is implemented,
@reflect()
decorator,@reflect
JSDoc tag orgetType<OfThatType>()
is required or there will be no Type metadata.Native types such as Object
{ foo: "", bar: 5 }
, Array[ {}, true, 5 ]
and primitive types are supported too; those types are recognized and their properties are parsed at runtime.Getters and setter of Objects are recognized.
Classes without metadata will be parsed as Objects.
Decorator.getArguments(): Array<any>
- constant literal arguments of decorators are captured,Type.isPrimitive()
,- partial test coverage (~75%) - issue #28,
TypeBuilder
,- decorator can be CallExpression
@decorator()
or (new) just Identifier@decorator
- implementation of #7 - custom Property and Method decorators supporting
getType<T>()
of generic parameters, like already supported class decorators.
- JSDoc tags @reflectGeneric and @reflectDecorator removed in favor of single @reflect,
Property.decorators
changed toProperty.getDecorators()
- to keep it same asType.getDecorators()
andMethod.getDecorators()
,Type.flattenInheritedMembers()
support base union and intersection types,- fixed issue #27,
- fix of some circular dependencies in runtime package,
- few other small bug fixes.