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

Declaration emit for private identifiers in class expressions is wrong #36548

Open
sandersn opened this issue Jan 31, 2020 · 3 comments
Open
Labels
Bug A bug in TypeScript Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone
Milestone

Comments

@sandersn
Copy link
Member

Code

const O = class { #g }

Expected behavior:

declare const O = class { #private }

Actual behavior:

declare const O: {
    new (): {
        "__#1@#g": any;
    };
};
@sandersn sandersn added this to the TypeScript 3.8.1 milestone Jan 31, 2020
@sandersn sandersn added the Bug A bug in TypeScript label Jan 31, 2020
@a-tarasyuk
Copy link
Contributor

@sandersn Should the ClassExpression be converted like ClassDeclaration?

For the following example, TS converts a variable value to type with the createTypeOfDeclaration, and in the checker, it seems that createAnonymousTypeNode doesn't handle cases for private identifiers.

const O = class { #g }

return cleanup(updateTypeScriptVariableDeclaration(input, input.name, /*exclaimationToken*/ undefined, ensureType(input, input.type), ensureNoInitializer(input)));

return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));

cc @rbuckton

@sandersn
Copy link
Member Author

sandersn commented Apr 6, 2020

That seems plausible. @rbuckton knows the transformer a lot better than I do though. Does that sound right to you?

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
@rbuckton
Copy link
Member

I'm not sure we can emit the declare const x = class { ... } form, as we generally use that to preserve literal type freshness. However, its possible we could leverage #41587 to address this with something like this:

declare const x = typeof class { #private };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

5 participants