Title: Experiment with always using parameters from base types for derived methods · Issue #23911 · microsoft/TypeScript · GitHub
Open Graph Title: Experiment with always using parameters from base types for derived methods · Issue #23911 · microsoft/TypeScript
X Title: Experiment with always using parameters from base types for derived methods · Issue #23911 · microsoft/TypeScript
Description: Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373. Goal We want to make it easier for users to derive types without rewriting the same parameter signature every time class Base { method(x: n...
Open Graph Description: Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373. Goal We want to make it easier for users to derive types without rewriting the same parameter signa...
X Description: Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373. Goal We want to make it easier for users to derive types without rewriting the same parameter signa...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/23911
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Experiment with always using parameters from base types for derived methods","articleBody":"Note some related issues for doing this with *properties* rather than methods: #3667, #6118, #1373.\r\n\r\n# Goal\r\n\r\nWe want to make it easier for users to derive types without rewriting the same parameter signature every time\r\n\r\n```ts\r\nclass Base {\r\n method(x: number) {\r\n // ...\r\n }\r\n}\r\n\r\nclass Derived extends Base {\r\n method(x) {\r\n // 'x' should have the type 'number' here.\r\n }\r\n}\r\n```\r\n\r\n# Potential ideas\r\n\r\n* Only enable in `noImplicitAny` (doesn't work for default initializers 😞)\r\n* Revert to `any` in all locations, opt in with another strictness flag (😞)\r\n* Something else? 😕\r\n\r\n# Potential issues\r\n\r\n## Default initializers with more capable derived types\r\n\r\n```ts\r\nclass A {\r\n a = 1;\r\n}\r\n\r\nclass B extends A {\r\n b = 2;\r\n}\r\n\r\nclass Base {\r\n method(x: A) {\r\n // ...\r\n }\r\n}\r\n\r\nclass Derived extends Base {\r\n method(x = new B) {\r\n x.b;\r\n // Today, 'x' has type 'B' which is technically unsound\r\n // but that's just what we do. Does changing this to 'A' break things?\r\n }\r\n}\r\n```\r\n\r\n## Default initializers that become less-capable via contextual types\r\n\r\n```ts\r\n\r\nclass Base {\r\n method(x: \"a\" | \"b\") {\r\n // ...\r\n }\r\n}\r\n\r\nclass Derived extends Base {\r\n method(x = \"a\") {\r\n // We have to make sure 'x' doesn't have type '\"a\"'\r\n // which is both unsound and less useful.\r\n }\r\n}\r\n```\r\n\r\n## Distinction between properties and methods\r\n\r\nWould this work?\r\n\r\n```ts\r\nclass Base {\r\n method = (x: number) => {\r\n // ...\r\n }\r\n}\r\n\r\nclass Derived extends Base {\r\n method(x) {\r\n // Does 'x' have the type 'number' here?\r\n }\r\n}\r\n```\r\n\r\nWhat about this?\r\n\r\n```ts\r\nclass Base {\r\n method(x: number) {\r\n // ...\r\n }\r\n}\r\n\r\nclass Derived extends Base {\r\n method = (x) => {\r\n // Does 'x' have the type 'number' here?\r\n }\r\n}\r\n```\r\n\r\n____\r\n\r\n**Keywords:** base type derived contextual contextually inherit methods implicit any","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2018-05-04T23:08:10Z","url":"https://github.com/microsoft/TypeScript/issues/23911"}
| 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:17bdf442-a8ec-23bc-510f-f8425ae03c07 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE56:B53AF:D53197:11CA3F1:6B00FFD3 |
| html-safe-nonce | 34e0678e7d5fcd190304ed329657c696d91e901c21e8d5f05cd53767f5c83221 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTU2OkI1M0FGOkQ1MzE5NzoxMUNBM0YxOjZCMDBGRkQzIiwidmlzaXRvcl9pZCI6Ijc1ODEwODcxMzU3NzI1MDgxMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5e7a35e5f9bbbe3e85ebf8881a43f9057879d1dbf1b1df258e137c0c695e8028 |
| hovercard-subject-tag | issue:320454689 |
| 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/23911/issue_layout |
| twitter:image | https://opengraph.githubassets.com/79c9e357f6f1beba98cf713cb5676bf6c843c8cf847ea14ac4a8593da9aeacb9/microsoft/TypeScript/issues/23911 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/79c9e357f6f1beba98cf713cb5676bf6c843c8cf847ea14ac4a8593da9aeacb9/microsoft/TypeScript/issues/23911 |
| og:image:alt | Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373. Goal We want to make it easier for users to derive types without rewriting the same parameter signa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| 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