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

"useDefineForClassFields" breaks ambient public fields #34972

Closed
robpalme opened this issue Nov 7, 2019 · 0 comments · Fixed by #35058
Closed

"useDefineForClassFields" breaks ambient public fields #34972

robpalme opened this issue Nov 7, 2019 · 0 comments · Fixed by #35058
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Fixed A PR has been merged for this issue High Priority

Comments

@robpalme
Copy link

robpalme commented Nov 7, 2019

TypeScript Version: 3.8.0-dev.20191105

Search Terms: declare ambient public class field useDefineForClassFields

Code

// Remember to enable compiler flag "useDefineForClassFields"
class C {
    declare field : any;
}

Expected behavior:

Ambient class fields should not be emitted.

Actual behavior:

The class field is included in the emitted JS code.

class C {
    constructor() {
        Object.defineProperty(this, "field", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
    }
}

When "useDefineForClassFields" is disabled, the declare keyword works correctly and omits the field. When "useDefineForClassFields" is enabled, the declare keyword fails and has no effect on emit. This means the field gets defined on the instance, even though the programmer wanted it to be omitted.

Playground Link:

Related Issues: #34942

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants