Giter Site home page Giter Site logo

Comments (6)

hugebdu avatar hugebdu commented on June 1, 2024

also capturing decorator args would be really great (primitives & enums)

class Entity {
  @Orm.Id(Orm.IdKind.AutoGenerated)
  id: string;
}

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

also capturing decorator args would be really great (primitives & enums)

class Entity {
  @Orm.Id(Orm.IdKind.AutoGenerated)
  id: string;
}

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.
So add Decorator.arguments: any[]?

from tst-reflect.

hugebdu avatar hugebdu commented on June 1, 2024

Decorator.arguments: any[]?

Sounds good 👍

Thanks

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

Fixed. Will be publish with other bug fixes in next version.

Contains fix of the decorators from different module and getArguments(): Array<any> on decorators.
Arguments must be Literal (string, number, boolean or enum. It can be value from const variable, even imported).
It is possible to allow Object litrals too, but it's a little tricky... I've kept it simple for this time...

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;
	}
}

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

Available from:

[email protected]
[email protected]

Version details in CHANGELOG

from tst-reflect.

hugebdu avatar hugebdu commented on June 1, 2024

awesome!
thanks @Hookyns

from tst-reflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.