microsoft / microsoft/TypeScript

Quick fix for using bracket accessor instead of get/set on Map

Open
#32,925 4 comments 2 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.