Title: Omit index signature with generic type constraints? · Issue #10941 · microsoft/TypeScript · GitHub
Open Graph Title: Omit index signature with generic type constraints? · Issue #10941 · microsoft/TypeScript
X Title: Omit index signature with generic type constraints? · Issue #10941 · microsoft/TypeScript
Description: TypeScript Version: nightly 2.1-20160914 I have a base class that takes a generic parameter with a constraint that is an index signature. Something like interface Constraint { [key: string]: number } class Base
Open Graph Description: TypeScript Version: nightly 2.1-20160914 I have a base class that takes a generic parameter with a constraint that is an index signature. Something like interface Constraint { [key: string]: number...
X Description: TypeScript Version: nightly 2.1-20160914 I have a base class that takes a generic parameter with a constraint that is an index signature. Something like interface Constraint { [key: string]: number...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10941
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Omit index signature with generic type constraints?","articleBody":"**TypeScript Version:** nightly 2.1-20160914\n\nI have a base class that takes a generic parameter with a constraint that is an index signature. Something like\n\n``` ts\ninterface Constraint {\n [key: string]: number\n}\n\nclass Base\u003cT extends Constraint> {\n entity: T\n}\n```\n\nThis class is meant to be inherited from and provided with another type that satisfies the index signature but doesn't carry it itself. Something like\n\n``` ts\ninterface MyType {\n prop: number;\n label: number;\n code: number\n}\n\nclass MyClass extends Base\u003cMyType> {\n // Error: Index signature is missing from MyType\n}\n```\n\nI don't want to put the index signature on MyType because destructuring `entity` won't output an error when the property doesn't exist:\n\n``` ts\nconst {id} = this.entity // oops, no error\n```\n\nwhich is a critical feature for me.\n\nI don't want to remove the index signature from the constraint because the base class completely revolves around it and I would lose a lot of type safety.\n\nIs there something I missed? Should we have some new language feature to solve this issue?\n\n(Now that I think of it I suppose it's a generic assignability issue between types, not restricted of type constraints, and it's not solved by #7029 since it's only about actual litterals, not types)\n","author":{"url":"https://github.com/JabX","@type":"Person","name":"JabX"},"datePublished":"2016-09-15T17:27:44Z","url":"https://github.com/microsoft/TypeScript/issues/10941"}
| 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:59125447-27e2-2d29-bc89-ad830c39d49b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8E8:2454CC:963E98:C08B38:6B00EFD5 |
| html-safe-nonce | b89e7ba583fad73be501245b9e8d091a93dfd26ee7837dc5eb5bab88bd224839 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEU4OjI0NTRDQzo5NjNFOTg6QzA4QjM4OjZCMDBFRkQ1IiwidmlzaXRvcl9pZCI6IjEyMzUyNjA1MzQ4ODcwODM5ODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5ea4e3f6e1ad19402fd3c1f04eb0a8471b764c6ed8c0954bdcefd493e96efcb6 |
| hovercard-subject-tag | issue:177236884 |
| 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/10941/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f2ee031da25c7f374a849ceeabaf05bda2a389a0636e8706fe6b51fb3b81556d/microsoft/TypeScript/issues/10941 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f2ee031da25c7f374a849ceeabaf05bda2a389a0636e8706fe6b51fb3b81556d/microsoft/TypeScript/issues/10941 |
| og:image:alt | TypeScript Version: nightly 2.1-20160914 I have a base class that takes a generic parameter with a constraint that is an index signature. Something like interface Constraint { [key: string]: number... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JabX |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width