Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class properties doesn't inherit types from interface #7011

Closed
alexdima opened this issue Feb 10, 2016 · 9 comments
Closed

Class properties doesn't inherit types from interface #7011

alexdima opened this issue Feb 10, 2016 · 9 comments
Labels
Duplicate An existing issue was already created

Comments

@alexdima
Copy link
Member

Moved from microsoft/vscode#2881
From @moostad

aaaa

@DanielRosenwasser
Copy link
Member

#6118 should fix this, right @sandersn?

@sandersn
Copy link
Member

No, #6118 only fixes contextual typing of implemented properties. The fix is probably related, but they are two separate bugs.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 12, 2016
@RyanCavanaugh
Copy link
Member

Raw notes


Where did it come from: base class or implemented interface
Is it: Initializer, property declaration, method declaration, or constructor declaration

  • Initializers of property declarations without type annotations
    • Contextually type from base class if it exists
    • Contextually type from implemented interfaces if all declarations have identical types
    • Otherwise none
  • Method declarations
    • Return expressions get contextually typed by base signature's return type
    • Unannotated parameters get contextually typed by base signature's parameter types
  • Unannotated uninitialized declarations
    • Simply get base type's type
    • foo; is as if you had written foo = undefined;, e.g. get foo: string if that was your base type's foo
  • Same for static declarations and constructor parameters

@mhegazy mhegazy added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Mar 7, 2016
@xzilja
Copy link

xzilja commented Nov 30, 2017

This still seems to be an issue, any development on it? Feels trivial to re-type everything that is already defined in implemented interface

@sandersn
Copy link
Member

We re-discuss it every six months or so, and haven't come up with any new ways to fix it without breaking old code.

@mhegazy mhegazy added In Discussion Not yet reached consensus and removed Help Wanted You can do this labels Nov 30, 2017
@robertdempsey
Copy link

robertdempsey commented Jan 11, 2018

@sandersn do you mean breaking old code that's out in the world that's not conforming to interfaces being implemented?

@sandersn
Copy link
Member

@robertdempsey See this comment in #6118 for details under the heading "The ugly". The code there is arguably correct, or at least useful, as-is.

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Feb 5, 2018
@RyanCavanaugh
Copy link
Member

Tracking at #10570 now

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

8 participants