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

Extended class does not satisfy requirement when defining default data without explicit type #32453

Closed
OrkhanAlikhanov opened this issue Jul 17, 2019 · 1 comment

Comments

@OrkhanAlikhanov
Copy link

OrkhanAlikhanov commented Jul 17, 2019

TypeScript Version: 3.5.3

Code

class Route {
  method: 'get' | 'post';
}

class MyRoute extends Route {
  method = 'get' // error?
  // method: 'get' = 'get' // compiles fine
}

Expected behavior:
Should compile fine by inheriting same type from base abstract class

Actual behavior:
Getting error:

TS2416: Property 'method' in type 'MyRoute' is not assignable to the same property in base type 'Route'.
Type 'string' is not assignable to type '"get" | "post"'.

Playground Link: http://www.typescriptlang.org/play/#code/IYIwzgLgTsDGEAJYBthjAgSgewK4QFMEBvAWACgEFRIZ4EBbAiAC2wBMAuBAcgHNmPBAB9eAB2yQeAbgoBfChRRoMAWQCeOfEQIAPQgDt2GLYRIUqTVh279BCALy8BEHvKA

@OrkhanAlikhanov OrkhanAlikhanov changed the title Extended abstract class does not satisfy requirement for property having string literal type Extended abstract class does not satisfy requirement when defining default data without explicit type Jul 17, 2019
@OrkhanAlikhanov OrkhanAlikhanov changed the title Extended abstract class does not satisfy requirement when defining default data without explicit type Extended class does not satisfy requirement when defining default data without explicit type Jul 17, 2019
@OrkhanAlikhanov
Copy link
Author

Duplicate of #32355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant