Skip to content

When the compile target is set to ES2022, an error will be reported at runtime #53218

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

Closed
Yuuki-Sakura opened this issue Mar 12, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Yuuki-Sakura
Copy link

Yuuki-Sakura commented Mar 12, 2023

Bug Report

πŸ”Ž Search Terms

ES2022 static member

πŸ•— Version & Regression Information

This is a crash

When a class has a static property and uses the class name when initializing and uses a decorator, an error will be reported at runtime

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export const Dec = (): ClassDecorator  => (target) => {

}

@Dec()
export class Test {
  // Using this.name and turning off useDefineForClassFields can eliminate runtime errors but need to use @ts-ignore
  static a = Test.name
}

console.log(Test.a)

πŸ™ Actual behavior

When run compiled javascript file will throw error:
Cannot read properties of undefined (reading 'name')

πŸ™‚ Expected behavior

console.log(Test.a) // should output 'Test'

possible solution

Remove the following compiled Test_1 variables will become normal

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Test = exports.Dec = void 0;
const Dec = () => (target) => {
};
exports.Dec = Dec;
let Test = class Test {
    static a = Test.name;
};
Test = __decorate([
    (0, exports.Dec)()
], Test);
exports.Test = Test;
console.log(Test.a); // output 'Test'
@fatcerberus
Copy link

Looks like a duplicate of #52004

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 14, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants