Title: Signatures of intersection/union types properties · Issue #9239 · microsoft/TypeScript · GitHub
Open Graph Title: Signatures of intersection/union types properties · Issue #9239 · microsoft/TypeScript
X Title: Signatures of intersection/union types properties · Issue #9239 · microsoft/TypeScript
Description: Consider next example: interface A{ f:string; set_f(val:string) : void; get_f() : string; } interface B{ f:number; set_f(val:number) : void; get_f() : number; } let n:number; let str:string let first : A&B; first.f = n; // error, as f ha...
Open Graph Description: Consider next example: interface A{ f:string; set_f(val:string) : void; get_f() : string; } interface B{ f:number; set_f(val:number) : void; get_f() : number; } let n:number; let str:string let fir...
X Description: Consider next example: interface A{ f:string; set_f(val:string) : void; get_f() : string; } interface B{ f:number; set_f(val:number) : void; get_f() : number; } let n:number; let str:string let fir...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9239
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Signatures of intersection/union types properties","articleBody":"Consider next example:\n\n```\ninterface A{\n f:string;\n set_f(val:string) : void;\n get_f() : string;\n}\n\ninterface B{\n f:number;\n set_f(val:number) : void;\n get_f() : number;\n}\n\nlet n:number;\nlet str:string\n\nlet first : A&B;\nfirst.f = n; // error, as f has type number&string. Probably OK, but probably it should be number|string, to be symmetric with set_f function.\nfirst.f = str; // error, as f has type number&string.\nn = first.f;\nstr = first.f;\n\nfirst.set_f(n);\nfirst.set_f(str);\nn = first.get_f(); // error, typescript prefer to use first signature () => string. Shouldn't it be string&number.\nstr = first.get_f();\n\nlet second : A|B;\nsecond.f = n; // Ops, no error! But it should be at least string&number here\nsecond.f = str;// Ops, no error! But it should be at least string&number here\nn = second.f; // error, typescript prefer to use first signature string. It should be string|number\nstr = second.f;// Ops, no error, typescript prefer to use first signature string. It should be string|number\n\nsecond.set_f(n); //error, lack a call signature. It's really good, but better if it would be (string&number) => void\nsecond.set_f(str); //error, lack a call signature. \nn = second.get_f(); // error, cool, typescript was able to correctly infer result as string|number\nstr = second.get_f();// error, cool, typescript was able to correctly infer result as string|number\n```\n\nWith #9167 additional to previous was added preserving readonly flag for intersection. Should't readonly flag be reset if any of intersection member has no such flag? As intersection should extend possibilities of type, and never narrow down it.\n","author":{"url":"https://github.com/iskiselev","@type":"Person","name":"iskiselev"},"datePublished":"2016-06-18T00:25:39Z","url":"https://github.com/microsoft/TypeScript/issues/9239"}
| 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:f6db819d-161e-88d1-c025-cf5f8c07037b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC98:157C65:64E0BA:88180A:6B00D742 |
| html-safe-nonce | caacf948456cc0a3eb6d62b435f0d97c32d1402ce6c780b9dda8d995c8e5860e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzk4OjE1N0M2NTo2NEUwQkE6ODgxODBBOjZCMDBENzQyIiwidmlzaXRvcl9pZCI6IjY3MzY0MDA5NzE4MjE3NzA5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8677638e76e1ea17dadc3cb4ce11308747111dd8bb23c940a2ff66306a2c1fab |
| hovercard-subject-tag | issue:160997143 |
| 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/9239/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b060b9cecc9429f3dab2d87e57978bc3321eebf2ff884a8cc37cbe9835c892c/microsoft/TypeScript/issues/9239 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b060b9cecc9429f3dab2d87e57978bc3321eebf2ff884a8cc37cbe9835c892c/microsoft/TypeScript/issues/9239 |
| og:image:alt | Consider next example: interface A{ f:string; set_f(val:string) : void; get_f() : string; } interface B{ f:number; set_f(val:number) : void; get_f() : number; } let n:number; let str:string let fir... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iskiselev |
| hostname | github.com |
| expected-hostname | github.com |
| None | a481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b |
| 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 | 84c8c5cc25e2fb7f2308428458538436baecc6d2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width