Title: Design Meeting Notes, 12/8/2017 · Issue #20724 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 12/8/2017 · Issue #20724 · microsoft/TypeScript
X Title: Design Meeting Notes, 12/8/2017 · Issue #20724 · microsoft/TypeScript
Description: in operators as a type guard interface Foo { abc: number; } interface Bar { def: string; } declare let x: Foo | Bar; if ("abc" in x) { x // Foo } else { x // Bar } Since types are open, in the true branch/then branch of the if, it"s not ...
Open Graph Description: in operators as a type guard interface Foo { abc: number; } interface Bar { def: string; } declare let x: Foo | Bar; if ("abc" in x) { x // Foo } else { x // Bar } Since types are open, in the true...
X Description: in operators as a type guard interface Foo { abc: number; } interface Bar { def: string; } declare let x: Foo | Bar; if ("abc" in x) { x // Foo } else { x // Bar } Since types are open, i...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20724
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 12/8/2017","articleBody":"# `in` operators as a type guard\r\n\r\n```ts\r\ninterface Foo {\r\n abc: number;\r\n}\r\n\r\ninterface Bar {\r\n def: string;\r\n}\r\n\r\ndeclare let x: Foo | Bar;\r\n\r\nif (\"abc\" in x) {\r\n x // Foo\r\n}\r\nelse {\r\n x // Bar\r\n}\r\n```\r\n\r\n\r\n* Since types are open, in the true branch/then branch of the `if`, it\"s not appropriate to say that the `x` *couldn't* be a `Bar`.\r\n * But we already have this behavior for property access expressions, and most of the time these things are intent-based.\r\n* Introduces a break to RxJS\r\n * https://github.com/ReactiveX/rxjs/blob/efcd922384116b2a45e7d7859e09cf6da34d7371/src/observable/dom/AjaxObservable.ts#L464-L474\r\n * Narrows value to `never` in the false branch/else branch of the conditional.\r\n * Declaration doesn't match reality on IE, but IE isn't following standard.\r\n * Technically should have a different declaration for IE.\r\n * Could introduce a type assertion/cast to get around this.\r\n * Should we only do this on unions?\r\n * No, need to be consistent with our narrowing behavior.\r\n* Conclusion\r\n * :+1:\r\n * Document that it's a breaking change.\r\n\r\n# The `override` keyword\r\n\r\n#2000\r\n#13217\r\n\r\n* Without flag, feature is not extremely useful.\r\n* What about `.d.ts` files?\r\n * Would users need `overrride`\r\n* Allow users to use `override` when flag is off.\r\n* With a flag, it's an error to not use `override`.\r\n* Would it go in `--strict`?\r\n * Not certain if it feels appropriate.\r\n* Generally, team feels ambivalent about whether the feature pays for its own complexity.\r\n * We're fans of being able to add extra enforcement, but this is extremely tied to inheritance.\r\n * Design time decorators? (#2900)\r\n * One day?\r\n* Marked as `Accepting PRs` last year.\r\n * Need to be discuss things more in depth before we decide these things.\r\n* Conclusion: can't accept at this time, would like to think more about annotations after decorators reach stage 3.\r\n\r\n# Conditional Types\r\n\r\n#12424\r\n\r\n* New type operator: `T extends U ? X : Y`\r\n * Breaks `T` does to its union constituents (or `T` itself if not a union), checks if each of those types is assignable to `U`.\r\n * When assignable, you get `X`, otherwise `Y`.\r\n * If `T` is not known, the type remains unevaluated.\r\n * Have been back and forth as to whether if `T` is a union, this distributes over the union.\r\n * In general, distributing over `T`seems to make the most sense.\r\n\r\n* Can make some handy types!\r\n\r\n ```ts\r\n type Diff\u003cT, U> = T extends U ? never : T;\r\n \r\n type TypeName\u003cT> = \r\n T extends string ? \"string\" :\r\n T extends number ? \"number\" :\r\n T extends boolean ? \"boolean\" :\r\n T extends undefined ? \"undefined\" :\r\n T extends Function ? \"function\" :\r\n T extends string ? \"string\" :\r\n \"object\";\r\n \r\n type NonNullable\u003cT> = Diff\u003cT, null | undefined>;\r\n \r\n type DeepReadonly\u003cT> = T extends object ?\r\n { readonly [P in keyof T]: DeepReadonly\u003cT[P]> } :\r\n T;\r\n \r\n // Type: \"a\" | \"d\"\r\n type T0 = Diff\u003c\"a\" | \"b\" | \"c\" | \"d\", \"b\" | \"c\">;\r\n \r\n // Type: \"string\" | \"function\"\r\n type T1 = TypeName\u003cstring | (() => void)>;\r\n \r\n // Type: string | number\r\n type T2 = Diff\u003cstring | number | (() => void), Function>;\r\n \r\n \r\n function f1\u003cT>(x: T, y: NonNullable\u003cT>) {\r\n x = y;\r\n y = x;\r\n }\r\n ```\r\n\r\n* How do these interact with `any` and `never`?\r\n * `any` gives both branches of the conditional.\r\n * `never` gives never.\r\n* Question: Should `T extends U` be a separate type operator from `X ? Y : Z`?\r\n* Should we have `&&` operators as well?`\r\n* If we did that, it introduces some more syntactical ambiguity.\r\n * Currently we deal with this by saying \"the ambiguities are rare for any useful code.\r\n * But `f\u003cT && U>(5)`, while a strange way to write `f \u003c T && U > 5`, feels odd.\r\n * `f\u003cT && U>`\r\n* What about inference for a given branch?\r\n * A new `infer` operator?\r\n * Maybe something like `type ReturnTypeOf\u003cT> = from T infer R in (...args: any[]) => R: R`\r\n * Note: would need a constraint on `T` like `(...args: any[]) => R`.\r\n * Then could deconstruct types anywhere?\r\n* Why did we move away from thinking about `match` types?\r\n * Kind of a \"Swiss army knife\" that does many things.\r\n * Has curlies which can confuse folks that might think it ends up being an object type.\r\n * Evaluation order might not be totally obvious to users, whereas conditionals are more explicit about order.\r\n* Does this give you the `awaited` type?\r\n * No.\r\n * Why not?\r\n * Evaluation of type aliases is eager, making them lazy would be difficult.\r\n * But if the type acted on isn't concrete, aren't we deferring evaluation anyway?\r\n * Maybe it does.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2017-12-15T20:04:30Z","url":"https://github.com/microsoft/TypeScript/issues/20724"}
| 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:a139f86b-d7b4-18b3-fd9f-24afe321edc5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A446:2564D8:8DF7EC:BDF540:6B00E149 |
| html-safe-nonce | 870f3263c357ed4fce96ed955ab51dfbad543bb2f27fa2940d4daff1bb89d50f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDQ2OjI1NjREODo4REY3RUM6QkRGNTQwOjZCMDBFMTQ5IiwidmlzaXRvcl9pZCI6Ijc3OTIzOTUwODU3Mzk1MTYyMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 597669fad4cab84686f557de00e7d2896e2ef698936e611579ff23de18713d76 |
| hovercard-subject-tag | issue:282533656 |
| 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/20724/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c73db0e3becdf84d340fda0767480bbe46e0e89d426e5a94c8bec5957d11fd94/microsoft/TypeScript/issues/20724 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c73db0e3becdf84d340fda0767480bbe46e0e89d426e5a94c8bec5957d11fd94/microsoft/TypeScript/issues/20724 |
| og:image:alt | in operators as a type guard interface Foo { abc: number; } interface Bar { def: string; } declare let x: Foo | Bar; if ("abc" in x) { x // Foo } else { x // Bar } Since types are open, in the true... |
| 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 | 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