Implement interface should not add optional properties
See original GitHub issueFrom 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;
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Force class to implement interface properties including optional
I'm looking for a way to force a class to implement all interface properties but keep them optional if they are in the...
Read more >TypeScript - Interfaces with Optional Properties - LogicBig
In TypeScript, the interfaces which describe objects can have optional properties. Interfaces with optional properties are written similar ...
Read more >c# - Implementing an interface when you don't need one of the ...
After all it's just a property. It could return 0 (the default property of int), or whatever value makes sense in your implementation...
Read more >Handbook - Interfaces - TypeScript
Not all properties of an interface may be required. Some exist under certain conditions or may not be there at all. These optional...
Read more >How to make Interface properties optional without changing ...
This approach will surely solve our error but we have a more elegant way to handle this rather than going to all interfaces...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why is this expected? It’s much easier to delete the optional properties/methods you don’t want than to track down the entire hierarchy of the target interface looking for them. We could add a comment or something or split it out into two commands if needed, but just opting them out feels like a regression in functionality.
I like that idea - I think displaying “implement required members” first, and then “implement all members”, is probably the right direction.
Any opinions @mjbvz?