Skip to content

No type inheritance for inherited properties when overridden #47966

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

Closed
maicol07 opened this issue Feb 19, 2022 · 2 comments
Closed

No type inheritance for inherited properties when overridden #47966

maicol07 opened this issue Feb 19, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@maicol07
Copy link

maicol07 commented Feb 19, 2022

Bug Report

πŸ”Ž Search Terms

property type inheritance

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
  p: true | 'string value' = true;
  o: {test: number} = {test: 1};
}

class B extends A {
  p = 'string value';
  o = {test: 5};
}

πŸ™ Actual behavior

Error when overriding the p property:

Property 'p' in type 'B' is not assignable to the same property in base type 'A'.
  Type 'string' is not assignable to type 'true | "string value"'.

πŸ™‚ Expected behavior

No errors, since the code is correct and types are respected

@MartinJohns
Copy link
Contributor

Duplicate of #10570.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 23, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants