microsoft / microsoft/TypeScript

Smarter errors around `Function.length`

Open
#35,404 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

I don't know how often other people have encountered this, but here goes: In the same vein as our uncalled function checks, most usages of Function.length are probably an error. Here's a toy example that just bit me:

declare function getResult(): string[];
for (let i = 0; i< getResult.length; i++) {
  getResult().slice(0, i).map(x => console.log(x));
}

Minimally, I think we could suggest that if a function returns something with a length property, and the function's length property is inspected instead, we could probably mark it as suspect.

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 by examining the existing uncalled function checks in the TypeScript compiler, then trace how function property access is analyzed. Define the intended diagnostic boundaries for inspecting Function.length when the function result has a length property, and add coverage showing when the usage is considered suspect.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.