Title: Bug: Class extending & incompatible methods · Issue #14288 · microsoft/TypeScript · GitHub
Open Graph Title: Bug: Class extending & incompatible methods · Issue #14288 · microsoft/TypeScript
X Title: Bug: Class extending & incompatible methods · Issue #14288 · microsoft/TypeScript
Description: TypeScript Version: 2.1.1 Code (playground link) interface Details { name: "Alex" | "Dan", age:number } class A { method(): Details { return { name: "Alex", // this doesn't fire any error age:30 } } } class B extends A { method() { retur...
Open Graph Description: TypeScript Version: 2.1.1 Code (playground link) interface Details { name: "Alex" | "Dan", age:number } class A { method(): Details { return { name: "Alex", // this doesn't fire any error age:30 } ...
X Description: TypeScript Version: 2.1.1 Code (playground link) interface Details { name: "Alex" | "Dan", age:number } class A { method(): Details { return { name: "Alex", // this do...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/14288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: Class extending & incompatible methods","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\r\n**TypeScript Version:** 2.1.1\r\n\r\n**Code** ([playground link](http://www.typescriptlang.org/play/#src=interface%20Details%20%7B%20%0D%0A%20%20%20%20name%3A%20%22Alex%22%20%7C%20%22Dan%22%2C%0D%0A%20%20%20%20age%3Anumber%0D%0A%7D%0D%0A%0D%0Aclass%20A%20%7B%0D%0A%20%20%20%20method()%3A%20Details%20%7B%20%0D%0A%20%20%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3A%20%22Alex%22%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20age%3A30%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aclass%20B%20extends%20A%20%7B%0D%0A%20%20%20%20method()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3A%20%22Alex%22%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20age%3A50%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%7D))\r\n\r\n```ts\r\ninterface Details { \r\n name: \"Alex\" | \"Dan\",\r\n age:number\r\n}\r\n\r\nclass A {\r\n method(): Details { \r\n return {\r\n name: \"Alex\", // this doesn't fire any error\r\n age:30\r\n }\r\n }\r\n}\r\n\r\nclass B extends A {\r\n method() {\r\n return {\r\n name: \"Alex\", // this fires an error\r\n age:50\r\n }\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo compilation errors\r\n\r\n**Actual behavior:**\r\n\r\nAn error that says:\r\n\r\n> Class 'B' incorrectly extends base class 'A'.\r\n Types of property 'method' are incompatible.\r\n Type '() => { name: string; age: number; }' is not assignable to type '() => Details'.\r\n Type '{ name: string; age: number; }' is not assignable to type 'Details'.\r\n Types of property 'name' are incompatible.\r\n Type 'string' is not assignable to type '\"Alex\" | \"Dan\"'.\r\n\r\n\r\nBut `method` in class B _is_ returning an object that is compatible with the declared interface an the error doesn't show up on class A `method`.","author":{"url":"https://github.com/alexcorvi","@type":"Person","name":"alexcorvi"},"datePublished":"2017-02-24T11:15:26Z","url":"https://github.com/microsoft/TypeScript/issues/14288"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b91413c-6485-c033-4ee9-69163ca7caea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADD0:22DB35:FACD08:142A66E:6B01005B |
| html-safe-nonce | 27570e82093522757fd1939a6d72df67338c57251f29d8ad00e06f9df0fea356 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREQwOjIyREIzNTpGQUNEMDg6MTQyQTY2RTo2QjAxMDA1QiIsInZpc2l0b3JfaWQiOiIxMzczNTczMTMxOTUxNzM0ODc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7cf21ca6f71fcdc9221ebcc16a93de7b7a5c7584f3722ccb1332b260a093edb1 |
| hovercard-subject-tag | issue:210022466 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/14288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80b07beb187e3f6b4711ce700e70315bfaaa010c766de2b1914e567de8f145e0/microsoft/TypeScript/issues/14288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80b07beb187e3f6b4711ce700e70315bfaaa010c766de2b1914e567de8f145e0/microsoft/TypeScript/issues/14288 |
| og:image:alt | TypeScript Version: 2.1.1 Code (playground link) interface Details { name: "Alex" | "Dan", age:number } class A { method(): Details { return { name: "Alex", // this doesn't fire any error age:30 } ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexcorvi |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width