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

tsc with allowJs reports TS9005 error for nested anonymous constructor functions #57523

Open
brian6932 opened this issue Feb 24, 2024 · 4 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@brian6932
Copy link

brian6932 commented Feb 24, 2024

🔎 Search Terms

TS9005: Declaration emit for this file requires using private name '(Anonymous function)'. An explicit type annotation may unblock declaration emit.

🕗 Version & Regression Information

Related to #55172
When 2 separate nested this bindings are used within constructor functions, the following error's returned always at the top of the file (this was really annoying to debug 😅)

Declaration emit for this file requires using private name '(Anonymous function)'. An explicit type annotation may unblock declaration emit.

⏯ Playground Link

https://tsplay.dev/NV57Gw

💻 Code

const a = new function () {
	this.b = new function () {
		this.c = 1
	}
}

🙁 Actual behavior

Complains

🙂 Expected behavior

Shouldn't complain

Additional information about the issue

No response

@rubiesonthesky
Copy link

Last typescript version in playground that does not report error is 3.6.2 so I don't think this changed in the linked PR.

In the linked issue #55172, weswigham notes that versions 3.6.6 do not show error that the code there is creating, so this probably is not working earlier versions either.

@Andarist
Copy link
Contributor

I'm not sure if this is meant to compile successfully but, if I'm reading this correctly, it shows an extra thing that is a bug. If you comment out the nested assignment to the this.c property then you might see this emit:

declare function a(): void;
declare class a {
    b: any;
}

This doesn't seem right because a is not a class - it's an instance of a class. Extra TS playground that shows the difference between anonymous and named functions here: TS playground

And an extra thing that I observed here, private name for #prop can leak in the declaration emit - this shouldn't happen (TS playground):

// input

// @target: esnext
function test() {
  return class A {
    #prop = 10;
  };
}

export const a = new (test())();

// dts
export declare const a: {
    "__#12@#prop": number;
};

@fatcerberus
Copy link

@Andarist Re: Private name leakage - #56145 -> #36548

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Feb 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 26, 2024
@kopax
Copy link

kopax commented Jul 4, 2024

Hello, any update on this ?

Using yarn4 and prisma, we get stuck as :

  • yarn4 can't generate prisma client in node_modules, so it is generated in the workspace with my files
  • I can't use annotation as this is often re-generated code

This makes me totally blocked and forced to downgrade yarn :(.

Any workaround exisiting ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

6 participants