Title: Rules for intersection types are inconsistent with rules for implementing multiple interfaces. · Issue #4278 · microsoft/TypeScript · GitHub
Open Graph Title: Rules for intersection types are inconsistent with rules for implementing multiple interfaces. · Issue #4278 · microsoft/TypeScript
X Title: Rules for intersection types are inconsistent with rules for implementing multiple interfaces. · Issue #4278 · microsoft/TypeScript
Description: It seems like the rules for a) implementing multiple interfaces and b) intersection types should be consistent. Example 1: Optional members interface A { m1: string;} interface B { m1?: string;} // allowed, m1 is required. type CT = A&B;...
Open Graph Description: It seems like the rules for a) implementing multiple interfaces and b) intersection types should be consistent. Example 1: Optional members interface A { m1: string;} interface B { m1?: string;} //...
X Description: It seems like the rules for a) implementing multiple interfaces and b) intersection types should be consistent. Example 1: Optional members interface A { m1: string;} interface B { m1?: string;} //...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4278
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Rules for intersection types are inconsistent with rules for implementing multiple interfaces.","articleBody":"It seems like the rules for **a)** implementing multiple interfaces and **b)** intersection types should be consistent.\n\nExample 1: Optional members\n\n``` ts\n interface A { m1: string;}\n interface B { m1?: string;}\n // allowed, m1 is required.\n type CT = A&B;\n var a : CT = {m1:undefined};// allowed, string can be undefined\n // error, m1 is required, \n //TS2322: Type '{}' is not assignable to type 'A & B', Property 'm1' is missing in type '{}'.\n var b : CT = {};\n\n // not allowed, TS2320, Named property 'm1' of types 'A' and 'B' are not identical.\n interface C extends A, B {}\n```\n\nExample 2: Protected members\n\n``` ts\n class P { protected m1: number; }\n class Q { m1: number; }\n // allowed, m1 is public\n type PQT = P&Q;\n var p : PQT = \u003cPQT>{m1:undefined};\n p.m1; // allowed, m1 is public in PQT\n\n // not allowed\n // TS2420: Class 'PQ' incorrectly implements interface 'Q'\n // Property 'm1' is protected in type 'PQ' but public in type 'Q'.\n class PQ extends P implements Q {}\n // TS2420: Class 'QP' incorrectly implements interface 'P'.\n // Property 'm1' is protected but type 'Q' is not a class derived from 'P'.\n class QP extends Q implements P {}\n\n // Allowed to relax protection explicitly in a derived class\n class PQX extends P implements Q { m1: number;}\n\n // Not allowed - again, seems a bug.\n class QPX extends Q implements P { m1: number;}\n\n // Workaround is to use an intermediate class to relax the protection\n class PX extends P {m1: number;}\n class QPX2 extends Q implements PX { m1: number;}\n```\n1. Implementing multiple interfaces should create a type which is the intersection of the types of the interfaces (but with any new members added).\n2. It should not be an error to make an optional member non-optional in a derived class. Non-optional members can be undefined, so nothing should break. This is consistent with intersection types. (Arguably also vice versa.)\n3. It should not be an error to relax the protected or private status of a member in a derived or implementing class, consistent with intersection types. (in 1.6 you can do it in a derived class but not an implementing class). Or at any rate it should be possible to do so if you need to. See also #3854 \n (Surely from a strict point of view Q above is a subtype of P, because it can be used wherever P is used. All members visible externally on P are visible externally on Q, and all members visible internally on P are visible internally on Q. So I think that makes Q a subtype of P.)\n\nImplementing two or more interfaces should create the same type as the intersection of the types. That they don't seems like a bug.\n\nIn pseudocode, this:\n\n``` ts\n interface C extends A, B {}\n```\n\nShould be identical in effect to this (if it was a thing):\n\n``` ts\n type C1 = A & B;\n interface C extends C1 {}\n```\n","author":{"url":"https://github.com/benliddicott","@type":"Person","name":"benliddicott"},"datePublished":"2015-08-11T19:05:44Z","url":"https://github.com/microsoft/TypeScript/issues/4278"}
| 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:f79ec6dc-0169-7cfc-fab3-788a014023e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E36A:24ACB9:95A647:C76925:6B00E155 |
| html-safe-nonce | 4137d450e74755b41d9745ce288b2625d85f3bcc283cd0397aa3cef425ddea06 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzZBOjI0QUNCOTo5NUE2NDc6Qzc2OTI1OjZCMDBFMTU1IiwidmlzaXRvcl9pZCI6IjE5Njg4NTU3NjEzNjMxOTMxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 74999df1a8edc51a9ab848fbfff561c20561cb707ecc4a6e6fea94b3e898e48e |
| hovercard-subject-tag | issue:100384015 |
| 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/4278/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e72dead1573a08e40fe39fd251b7915ef7f4de67c79ff24eff4d250aa4802cf3/microsoft/TypeScript/issues/4278 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e72dead1573a08e40fe39fd251b7915ef7f4de67c79ff24eff4d250aa4802cf3/microsoft/TypeScript/issues/4278 |
| og:image:alt | It seems like the rules for a) implementing multiple interfaces and b) intersection types should be consistent. Example 1: Optional members interface A { m1: string;} interface B { m1?: string;} //... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | benliddicott |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width