Title: Design Meeting Notes for 2/05/2016 · Issue #6930 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes for 2/05/2016 · Issue #6930 · microsoft/TypeScript
X Title: Design Meeting Notes for 2/05/2016 · Issue #6930 · microsoft/TypeScript
Description: Joke of the day Anders: "What do you call a fish without an eye?" "Fsh!" Breaking Changes "use strict" changes for modules (#3676) Requested by several people. Broke several people. New flag Yay, new flags! Today's flag is... emitNonStri...
Open Graph Description: Joke of the day Anders: "What do you call a fish without an eye?" "Fsh!" Breaking Changes "use strict" changes for modules (#3676) Requested by several people. Broke several people. New flag Yay, n...
X Description: Joke of the day Anders: "What do you call a fish without an eye?" "Fsh!" Breaking Changes "use strict" changes for modules (#3676) Requested by several people. Broke s...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6930
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes for 2/05/2016","articleBody":"# Joke of the day\n- Anders: \"What do you call a fish without an eye?\"\n - \"Fsh!\"\n# Breaking Changes\n## \"use strict\" changes for modules (#3676)\n- Requested by several people.\n- Broke several people.\n- New flag\n- Yay, new flags!\n- Today's flag is...\n - `emitNonStrictModules`.\n - Keeps compliance, but allows people to revert behavior.\n - Do we emit `\"use strict\"` for classes?\n - No.\n - We should.\n - Should this flag affect that when we make that change?\n - Yes, let's give the flag a better name to reflect that.\n - Would we be breaking people if we actually did this though?\n - Apparently yes.\n## Defaulting to built-in promises\n- We used to use type annotations as a guide to enable a bring-your-own-promise scenario.\n - Doesn't match with semantics reflecting original spec.\n - Breaks design goals.\n- Could we remove the restriction for ES6 (ES7?) and prior?\n - Sure?\n- Options:\n - Keep breaking change\n - Undo the change, perform the breaking change when we actually have downlevel `async`/`await`.\n- Resolution: undo the change, apply it when we actually allow users to downlevel their `async` code.\n# Features (and potential breaking changes)\n## Specifying `this` types for functions (#6739)\n- What does the \"strict `this`\" world look like?\n- We will check `this` just as if it was an argument today.\n- Consider\n \n ``` ts\n class Foo {\n m() {\n this.blah();\n // ...\n }\n \n blah() {\n // ...\n }\n }\n \n let foo: Foo;\n let e: () => void = foo.m;\n e();\n ```\n - That example will crash because `m` has been orphaned from its `Foo` instance.\n- Strict `this`-checking aims to fix this issue.\n- `this` appears in the parameter list for functions and function types.\n- `this` types affect assignability of signatures:\n \n ``` ts\n type EventA = (this: Element, x: string) => void;\n \n type EventB = (this: void, x: string) => void;\n \n let a: EventA;\n let b: EventB;\n \n a = b; // Error: 'void' isn't enough for a method needing an 'Element' for 'this'.\n b = a; // Okay: No problem with getting *more* than you expect.\n ```\n - Assignability is still bivariant for a `this` parameter\n- In strict-`this` mode, the following's an error:\n \n ``` ts\n function foo(s: string) {\n this.abc; // Error: 'this' is implicitly a 'void'.\n }\n ```\n- Arrow functions will _always_ hold the value of `this` from their containing scope.\n- Free-standing functions implicitly get a `void` type for `this`.\n- Methods in classes implicitly have a `this` type of `this`.\n - Hopefully this is not very surprising.\n - This prevents incorrectly \"ripping off the method\" (`this` orphaning) from the first example.\n- Static methods have a `this` type of `typeof Foo` where `Foo` is the containing class. \n- Does this fix the `bind` function?\n - Almost!!\n- Why do we need a flag?\n - It breaks existing code for when your methods have no dependency on `this`.\n - Occurs several types in the compiler.\n - Problems sprout up between methods signatures and function type literals:\n \n ``` ts\n interface Foo {\n a(): void;\n b(): void;\n }\n \n interface Bar {\n a: () => void;\n b: () => void;\n }\n ```\n - `Foo` methods implicitly get a `this: this` type, while `Bar` methods get a `this: void` type!\n - We need to be prescriptive and explain to people how to write definitions.\n - People are still going to run into such gotchas.\n- By default, without the strict-`this` flag, there will be no implied `this` type.\n- But we still want contextual typing to work correctly:\n \n ``` ts\n addOnClick(function (e) {\n // 'this' has the 'Element' type.\n this./*|*/\n // |\n // +-- Members of the 'Element' type.\n });\n ```\n- What about object literals?\n - If the object is contextually typed by `X`, methods will get the `this` type of `X`.\n \n ``` ts\n var o: X = {\n x: 10,\n m() {\n this // has type 'X'\n }\n }\n ```\n - An object literal with no contextual type just grabs the type of the object literal:\n \n ``` ts\n var o: X = {\n x: 10,\n m() {\n this // has type '{ x: number; m(this: /*typeof o?*/); }}'\n }\n }\n ```\n - Uh-oh, how will the declaration emitter and language-service print the type of `o`?\n- Speaking of surfacing the representation of these types...\n \n ``` ts\n interface Foo {\n bar();\n }\n // What is the type of 'foo'? (this: this) => void?\n const foo = foo.bar;\n ```\n- So are all these very big changes going to need these sorts of flags?\n - Are we going to have a \"very strict mode\"?\n- Do overload `this` parameters need to match?\n - No.\n## Unique types/tagged types/opaque types\n- People keep asking for this.\n- Ideas from last time:\n \n ``` ts\n unique class C {\n // ...\n }\n \n unique interface I {\n // ...\n }\n \n unique type Path = string;\n ```\n- The biggest question last time was what the behavior was for the type alias example (i.e. `Path`).\n- We're thinking that\n \n ``` ts\n type Path = string & (unique {});\n ```\n - We can also do some stuff so that `Path` will be printed as `Path`.\n- This approach, combined with intersections, allows you to \"compose\" on existing types.\n- You can write `Path & Lowercased`.\n- Unique interfaces are useful for preventing people from forging nodes.\n- What about if a base is unique?\n- Does `unique` affect the static side?\n - Maybe?\n - Actually, you get that for free because the constructor function returns a unique type.\n - Well almost. But that would require a type assertion anyhow.\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2016-02-05T20:32:05Z","url":"https://github.com/microsoft/TypeScript/issues/6930"}
| 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:7c6000a3-57f4-b95c-875d-d5c4acf2fea4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9C0:2D96F1:586898:77ADAB:6B00D087 |
| html-safe-nonce | 921f997c8894cf2bc61bde79fa7744b2df7b78b385ed997327835a409fa62389 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUMwOjJEOTZGMTo1ODY4OTg6NzdBREFCOjZCMDBEMDg3IiwidmlzaXRvcl9pZCI6IjM1Mzk2MzgwNDU0MjQ3OTk4NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b885ebbbac1c0308e90c3809943c80fdb24da537cb47440347c036dad6e38c59 |
| hovercard-subject-tag | issue:131748591 |
| 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/6930/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c2177c5ff996d0da49fc429c7d85252d1e99bccda769e3bde54a347b50d0091/microsoft/TypeScript/issues/6930 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c2177c5ff996d0da49fc429c7d85252d1e99bccda769e3bde54a347b50d0091/microsoft/TypeScript/issues/6930 |
| og:image:alt | Joke of the day Anders: "What do you call a fish without an eye?" "Fsh!" Breaking Changes "use strict" changes for modules (#3676) Requested by several people. Broke several people. New flag Yay, n... |
| 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 | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| 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 | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width