microsoft / microsoft/TypeScript

Implement interface should not add optional properties

Open
#22,770 12 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: LS: Quick Fixes Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

From https://github.com/Microsoft/vscode/issues/46286

TypeScript Version: 2.8.0-dev.20180320

Search Terms:

  • implement interface
  • quick fix
  • code action
  • optional property

Code

interface IFoo {
    x?: number
    y: number
}

class Foo implements IFoo {

}

Trigger implement interface on Foo

Expected behavior:
Only required properties required:

interface IFoo {
    x?: number
    y: number
}

class Foo implements IFoo {
    y: number;
}

Actual behavior:
Both required and optional properties added:

interface IFoo {
    x?: number
    y: number
}

class Foo implements IFoo {
    x?: number;
    y: number;
}

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 at the TypeScript language-service code action invoked by “implement interface” and reproduce the provided IFoo/Foo example. Check the generated implementation members, then verify that only the required y property is added while optional x is omitted.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.