microsoft / microsoft/TypeScript

unused local not detected on recursive functions

Open
#45,360 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Something Else
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

unused local recursive function

🕗 Version & Regression Information

v4.5.0-dev.20210807

⏯ Playground Link

Playground link with relevant code

💻 Code
export {}

//no error even though foo is never read
const foo = () => {
    foo()
}

//error: 'bar' is declared but its value is never read.(6133)
const bar = () => {}
🙁 Actual behavior

no error even though foo is never read

🙂 Expected behavior
'foo' is declared but its value is never read.(6133)

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 and reproduce the difference between the recursive foo function and the unused bar function with noUnusedLocals enabled. The payload names no source file or test, so trace the compiler's unused-local analysis from this reproduction. Done means the recursive declaration reports diagnostic 6133 without incorrectly changing the bar behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.