-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prop decorators defined in a different compilation unit? #27
Comments
also capturing decorator args would be really great (primitives & enums)
|
This is related with #7 There is no problem to support property decorators and allow them to get type of class via generic type. So it is possible to start from other side from that decorator, with all the runtime arguments of that decorator and get type of class. That's the point in #7. Your point is good too. If it is constant value, capture it. |
Sounds good 👍 Thanks |
Fixed. Will be publish with other bug fixes in next version. Contains fix of the decorators from different module and import {
getType,
reflect
} from "tst-reflect";
import { SomeEnum } from "./SomeEnum";
import { SomeString } from "./SomeType";
const MyString = "SomeType";
function klass<TType>(str: string, num: number, enu: SomeEnum)
{
console.log("klass", str, num, enu, getType<TType>());
return function <T>(Constructor: { new(...args: any[]): T }) {
};
}
function property(str: string, num: number, enu: SomeEnum, any: any)
{
console.log("property", str, num, enu, any);
return function (_, __) {};
}
@klass(MyString, 5, SomeEnum.One)
class A
{
@property("Foo property", 5, SomeEnum.One, { foo: "f", bar: 5, baz: SomeEnum.Two })
foo: string;
@property(SomeString, 5, SomeEnum.Two, true)
get bar(): number
{
return 0;
}
} |
- new! literal arguments of decorators captured -> Decorator.getArguments(): Array<any> - decorator can be CallExpression`@decorator()` or (new) just Identifier `@decorator` - TypeBuilders - getType(val: any) on runtime value - preparation - fix of some circular dependencies in runtime package - Null metadata Store
### Added - `getType(val: any)` it is possible to get type of runtime value, <dl> <dd> ```typescript const someValue: unknown = new Animal(); getType(someValue); // > Type<Animal> ``` This works mainly with classes. Before #29 is implemented, `@reflect()` decorator, `@reflect` JSDoc tag or `getType<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.* </dd> </dl> - `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. ### Changed - JSDoc tags @reflectGeneric and @reflectDecorator removed in favor of single @reflect, - `Property.decorators` changed to `Property.getDecorators()` - to keep it same as `Type.getDecorators()` and `Method.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.
Available from:
Version details in CHANGELOG |
awesome! |
Trying to use class prop decorator - works perfect when resides in the same source file with the property being decorated, but if the decorator is imported from another source file, I get
Property#decorators
emptyThe text was updated successfully, but these errors were encountered: