Open
Description
🔎 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
- Occurs on versions 3.7.5 - nightly
- Related to PR Avoid trying to emit anonymous classish/expando functions as assignments #55472
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
💻 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rubiesonthesky commentedon Feb 25, 2024
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 commentedon Feb 25, 2024
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: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 playgroundAnd an extra thing that I observed here, private name for
#prop
can leak in the declaration emit - this shouldn't happen (TS playground):fatcerberus commentedon Feb 26, 2024
@Andarist Re: Private name leakage - #56145 -> #36548
kopax commentedon Jul 4, 2024
Hello, any update on this ?
Using yarn4 and prisma, we get stuck as :
This makes me totally blocked and forced to downgrade yarn :(.
Any workaround exisiting ?
Jeangowhy commentedon Nov 8, 2024
Can someone tell what is this problem?
seahindeniz commentedon Apr 20, 2025
In my case,
"composite": true,
was in my tsconfig.json file. Removing it solved the issue