microsoft / microsoft/TypeScript
Smarter errors around `Function.length`
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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