microsoft / microsoft/TypeScript

Generated d.ts includes implicit any for recursive types

Open
#55,832 9 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.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

recursive any noImplicitAny d.ts

🕗 Version & Regression Information
  • This is the behavior in every version I tried (3.3 through 5.2), and I reviewed the FAQ for entries about anything related to this.
⏯ Playground Link

playground link

💻 Code
const a = () => a;
🙁 Actual behavior

Any is implicitly introduced in the d.ts:

declare const a: () => any;

Note that the local type checking (not using the d.ts) correctly handles this recursive type without introducing "any", and builds fine with noImplicitAny enabled.

🙂 Expected behavior

Either generate something without implicitly introducing any, or generate an error if noImplicitAny is enabled.
In this case, the below code generation for the d.ts would work:

declare const a: () => typeof a;
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 Playground reproduction and compare the generated declaration for const a = () => a with the expected typeof a form. Trace the declaration-generation path for this recursive type and add or update a regression test for noImplicitAny. Done means recursive declarations no longer introduce implicit any, or an appropriate error is reported.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.