microsoft / microsoft/tsyringe

Class properties are lost when decorating on Node 13.X

Open
#89 0 comments 3 reactions 1 assignee View on GitHub

@Xapphire13 is already working on this.

Since Jan 30, 2020.

awaiting triage
Dominant language
TypeScript
Stars
6k
Forks
184
Avg merge
3m
Merged PRs (30d)
1

Description

Describe the bug
When using Node 13, accessing the constructor property of the class is hidden by the decorators of tsyringe.

To Reproduce

import "reflect-metadata";

import { autoInjectable } from "tsyringe";

abstract class Service {
  serviceName(): string {
    return this.constructor.name;
  }
}

function printClass<T extends Service>(): (target: any) => void {
  return function(target: any): void {
    console.log("Decorator for: ", target.name);
  };
}

@printClass()
@autoInjectable()
class AutoInjectableClass extends Service {}
console.log("AutoInjectable instance name: ", new AutoInjectableClass().serviceName());

@printClass()
class RegularClass extends Service {}
console.log("Regular instance name: ", new RegularClass().serviceName());

Node 13.X:

Decorator for:  
AutoInjectable instance name:  
Decorator for:  RegularClass
Regular instance name:  RegularClass

Expected behavior
Node 12.X:

Decorator for:  AutoInjectableClass
AutoInjectable instance name:  AutoInjectableClass
Decorator for:  RegularClass
Regular instance name:  RegularClass

Version:
Node > 13.0
Tsyringe 3.7.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.