microsoft / microsoft/TypeScript
Quick fix for using bracket accessor instead of get/set on Map
Open
Nobody has claimed this yet.
Domain: LS: Quick Fixes
Experience Enhancement
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.6.0-dev.20190814
Search Terms:
- quick fix
- code action
- getCodeFixes
Code
With strict: true:
class Foo {
public readonly map = new Map<string, string>();
constructor() {
console.log(this.map['af123']);``
}
}
This produces the error:
Element implicitly has an 'any' type because type 'Map<string, string>' has no index signature. Did you mean to call 'get' ?
Expected behavior:
The error message suggests a fix. We should should be a quick fix that changes the code to call .get
Actual behavior:
No quick fix returned.
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 searching the TypeScript code-action implementation and getCodeFixes handling for the diagnostic shown in the issue. Reproduce the Map bracket-access example with strict mode, then verify that a quick fix is offered and changes the access to a get call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100