Title: Support for optional abstract members in an abstract class body · Issue #22939 · microsoft/TypeScript · GitHub
Open Graph Title: Support for optional abstract members in an abstract class body · Issue #22939 · microsoft/TypeScript
X Title: Support for optional abstract members in an abstract class body · Issue #22939 · microsoft/TypeScript
Description: TypeScript Version: 2.8.0-insiders.20180320 (version currently running in playground) Search Terms: abstract optional Code abstract class Foo { abstract foo(): void abstract bar?(): void } // Non-abstract class Bar missing abstract membe...
Open Graph Description: TypeScript Version: 2.8.0-insiders.20180320 (version currently running in playground) Search Terms: abstract optional Code abstract class Foo { abstract foo(): void abstract bar?(): void } // Non-a...
X Description: TypeScript Version: 2.8.0-insiders.20180320 (version currently running in playground) Search Terms: abstract optional Code abstract class Foo { abstract foo(): void abstract bar?(): void } // Non-a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22939
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for optional abstract members in an abstract class body","articleBody":"**TypeScript Version:** 2.8.0-insiders.20180320 (version currently running in playground)\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** \r\nabstract optional\r\n\r\n**Code**\r\n\r\n```ts\r\nabstract class Foo {\r\n abstract foo(): void\r\n abstract bar?(): void\r\n}\r\n\r\n// Non-abstract class Bar missing abstract member bar\r\nclass Bar extends Foo {\r\n foo() { return }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nIt should be possible to omit the definition of `bar` in the `Bar` class.\r\n\r\nIf something constructs an instance of `Bar`, it should not be possible to call `new Bar().bar()`, either because it is considered `undefined` or because it still retains some \"abstractedness\".\r\n\r\nThe intent is to use this in type definitions where subclasses can optionally define methods that will be called by their superclass; similar to lifecycle events in `React.Component`.\r\n\r\nNot making them abstract allows things such as calling `super.componentDidMount()` even though it does not exist in `React.Component`'s prototype, or having a subclass without their own `render()` implementation because TypeScript thinks it is provided by `React.Component`.\r\n\r\nSupporting optional abstract members could also be used to guard against the common error of not initializing `state` on classes that use `this.state` -- it does not actually exist until either the first `setState` call or until `this.state` is assigned, and initializing `this.state` by assignment is far more common than initializing it with `setState`.\r\n\r\n**Actual behavior:**\r\nIt's not possible to omit it unless `bar = undefined` is specifically added to `Bar`\r\n\r\n**Playground Link:** [Playground Link](https://www.typescriptlang.org/play/index.html#src=abstract%20class%20Foo%20%7B%0A%20%20%20%20abstract%20foo()%3A%20void%0A%20%20%20%20abstract%20bar%3F()%3A%20void%0A%7D%0A%0Aclass%20Bar%20extends%20Foo%20%7B%0A%20%20%20%20foo()%20%7B%20return%20%7D%0A%7D%0A)\r\n","author":{"url":"https://github.com/Jessidhia","@type":"Person","name":"Jessidhia"},"datePublished":"2018-03-28T01:55:13Z","url":"https://github.com/microsoft/TypeScript/issues/22939"}
| 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:4cb73c9f-2347-d96d-994b-13524acdaaa4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF44:27E5CD:35C93F5:44CE2F5:6B01DD12 |
| html-safe-nonce | 29253d995746409e413e2f6d16a1e928144ccdc0e0cd7c977616cd644179ccae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjQ0OjI3RTVDRDozNUM5M0Y1OjQ0Q0UyRjU6NkIwMUREMTIiLCJ2aXNpdG9yX2lkIjoiODY5ODU3Nzg0NDU0MTk3MTczMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8b563b779e71ac44e1ccf9559bf7c12b88d0eda848f937060a291873a13dc22 |
| hovercard-subject-tag | issue:309193495 |
| 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/22939/issue_layout |
| twitter:image | https://opengraph.githubassets.com/392db7e3508d75e27c254070bd70f94f5bb06020c94c3f5d5b8d60bfd5f81baf/microsoft/TypeScript/issues/22939 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/392db7e3508d75e27c254070bd70f94f5bb06020c94c3f5d5b8d60bfd5f81baf/microsoft/TypeScript/issues/22939 |
| og:image:alt | TypeScript Version: 2.8.0-insiders.20180320 (version currently running in playground) Search Terms: abstract optional Code abstract class Foo { abstract foo(): void abstract bar?(): void } // Non-a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Jessidhia |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width