Skip to content
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

The process of Decorator has mistake make the PropertyDescriptor with undefined value #547

Open
JiaHenry opened this issue Mar 4, 2022 · 0 comments

Comments

@JiaHenry
Copy link

JiaHenry commented Mar 4, 2022

Please try with the code in TypeScript Playground

or the source code:
`// @experimentalDecorators
function LogMethod(
target: any,
propertyKey: string | symbol,
descriptor: PropertyDescriptor
) {
console.log(target);
console.log(propertyKey);
console.log(descriptor);
}

class Demo {
@logmethod
public static foo(bar: number) {
// do nothing
}

@logmethod
public foo2(bar: number) {
// do nothing
}
}

const demo = new Demo();
Demo.foo(10);
demo.foo2(12);`

The output of js with something like __decorate(([...], Demo.prototype, "foo2", null)
but the karma-typescript output code like __decorate([LogMethod], Demo.prototype, 'foo2')

the missing null at end will make the code in __decorate as following:
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc
make the desc keep the undefined value because undefined === null is false.

Please see bellow pictures about the output.
The is the output in TypeScript Playground
typescript

And the output of karma
karma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant