Title: add object initializers · Issue #8545 · microsoft/TypeScript · GitHub
Open Graph Title: add object initializers · Issue #8545 · microsoft/TypeScript
X Title: add object initializers · Issue #8545 · microsoft/TypeScript
Description: Currently there are 2 ways to enforce implementing an interface over an object: creating a object literal in an interface type context constructing an instance of a class that implements the said interface In both cases we deal with a ne...
Open Graph Description: Currently there are 2 ways to enforce implementing an interface over an object: creating a object literal in an interface type context constructing an instance of a class that implements the said i...
X Description: Currently there are 2 ways to enforce implementing an interface over an object: creating a object literal in an interface type context constructing an instance of a class that implements the said i...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/microsoft/TypeScript/issues/8545
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"add object initializers","articleBody":"Currently there are 2 ways to enforce implementing an interface over an object:\n- creating a object literal in an interface type context\n- constructing an instance of a class that implements the said interface\n\nIn both cases we deal with a newly created object, however there are also situations when an already created object needs to be extended to comply to some more elaborate interface.\n\nA good example are mixins and scenarios alike:\n\n``` typescript\ninterface DoThis {\n x: any;\n y: any;\n}\ninterface DoThat {\n z: any\n}\ninterface DoBoth implements DoThis, DoThat {\n}\n\nfunction extend(doThis: DoThis): DoBoth {\n // need to make sure that all properties of DoThat are set\n // wish could do just\n // doThis.z = undefined;\n // return doThis;\n // have to do\n return {\n x: doThis.x,\n y: doThis.y\n z: undefined\n };\n}\n\nlet doThis : DoThis = { x: undefined, y: undefined };\nlet doBoth = extend(doThis);\n```\n\nI am not aware how to make the extend function type safe, other than copying each field from `doThis` to the resulting object. Which might or might not be a solution (functions are harder to extend this way). If only TypeScript had a way to enforce an interface on the given object it would be very helpful.\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2016-05-10T15:33:00Z","url":"https://github.com/microsoft/TypeScript/issues/8545"}
| 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:3c8bdb7d-5d37-8531-66db-5b8437a4a450 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97D8:2E5652:17AFF3:1EF6B7:6B00C9AD |
| html-safe-nonce | 7da0de5df945a40135b1f489f936cf26ba9381e4b875a987c74b9603e7f8c978 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0Q4OjJFNTY1MjoxN0FGRjM6MUVGNkI3OjZCMDBDOUFEIiwidmlzaXRvcl9pZCI6IjI4MjU4NzQ1ODAzMDY5NzEwNTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d821719966003a8a05150477fadaf139a7ea56e67da1dcd5471d9a8dd913ef42 |
| hovercard-subject-tag | issue:154037156 |
| 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/8545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b68ec1365338e4d0a6ce07eab6152e7a9387f73cee7f8312774be7eac22bc3c4/microsoft/TypeScript/issues/8545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b68ec1365338e4d0a6ce07eab6152e7a9387f73cee7f8312774be7eac22bc3c4/microsoft/TypeScript/issues/8545 |
| og:image:alt | Currently there are 2 ways to enforce implementing an interface over an object: creating a object literal in an interface type context constructing an instance of a class that implements the said i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zpdDG4gta8XKpMCd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width