microsoft / microsoft/TypeScript

tsc with allowJs reports TS9005 error for nested anonymous constructor functions

Open
#57,523 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Declaration Emit Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

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 #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

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground reproduction and read PR #55472 and issue #55172 for the related declaration-emit behavior. The work is done when the nested anonymous constructor example with allowJs no longer reports TS9005 while declaration emit still succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.