Giter Site home page Giter Site logo

Comments (7)

avin-kavish avatar avin-kavish commented on June 7, 2024 1

What I did is more like this. The link is not running but I think you can check the generated code.

from tst-reflect.

Hookyns avatar Hookyns commented on June 7, 2024

@avin-kavish

It works for me.

import { getType } from "tst-reflect";

function entity(_: any)
{
}

@entity
export class Cat
{
	id = 0;
	toys: Toy[] = [];
}

@entity
export class Toy
{
	id = 0;
}

const type = getType<Toy>();
type.getCtor().then(ctor => console.log(ctor)); // It prints [class Toy]; working with Cat class too.

Can you send repro, eg. on StackBlitz?

from tst-reflect.

Hookyns avatar Hookyns commented on June 7, 2024

Okay, there are three issues.

  • First issue is not generated "ctor" property.

  • Second issue is how decorators work.
    There is __decorate call inside generated TypeScript which is called before type is exported from the module so you cannot import it from the decorator. This is a "no go".
    You will receive type, there is no problem, but import is gonna return undefined, always.
    Solution is simple. Use decorator's parameter. First parameter is the decorated class.

/**
 * @reflect
 */
export function entity<TType extends Function>(Class: TType) {
	const typeT = getType<TType>();
	console.log(typeT.name, Class);
}
  • And there is the third problem. Simple decorators are broken, cuz of how I handle them so you will never receive the decorated target.

I've already fixed the issue with decorators (in [email protected]) so you can use the solution from the second point.
Meanwhile, I will fix the issue from the first point, but you cannot use it in decorator anyway.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 7, 2024

Alright. Actually, 2nd point is not a problem. I did it that way just for the stackblitz example. In my actual implementation I push it to a container and later once all the modules are loaded, I check the types.

/**
 * @reflect
 */
export function entity<TType extends Constructor>(_: any) {
  const typeInfo = getType<TType>()
  EntityTypeStore.push(typeInfo)
}

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 7, 2024

It's happening here also. https://stackblitz.com/edit/tst-reflect-issue-49-htnd32?file=package.json,index.ts

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 7, 2024

Happened again. This time seemingly random, class next to it gets imported just fine.

from tst-reflect.

Hookyns avatar Hookyns commented on June 7, 2024

Fixed in v1. Not in the current version.

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.