Title: Design Meeting Notes for 3/11/2016 · Issue #7488 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes for 3/11/2016 · Issue #7488 · microsoft/TypeScript
X Title: Design Meeting Notes for 3/11/2016 · Issue #7488 · microsoft/TypeScript
Description: Non-nullable types (#7140) Question marks on types Let's start the bike-shedding! What does T? mean? function foo(x?: string) { // x: string | undefined } function foo(x: string?) { // ????? } function foo(x?: string?) { // x: string | u...
Open Graph Description: Non-nullable types (#7140) Question marks on types Let's start the bike-shedding! What does T? mean? function foo(x?: string) { // x: string | undefined } function foo(x: string?) { // ????? } func...
X Description: Non-nullable types (#7140) Question marks on types Let's start the bike-shedding! What does T? mean? function foo(x?: string) { // x: string | undefined } function foo(x: string?) { // ????? } ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7488
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes for 3/11/2016","articleBody":"# Non-nullable types (#7140)\n## Question marks on types\n\nLet's start the bike-shedding! What does `T?` mean?\n\n``` ts\nfunction foo(x?: string) {\n // x: string | undefined\n}\n\nfunction foo(x: string?) {\n // ?????\n}\n\nfunction foo(x?: string?) {\n // x: string | undefined | ?????\n}\n```\n- @ahejlsberg: It's hard to imagine a world where `T?` means _only_ `T | null` or _only_ `T | undefined`.\n- There is a school of thought that says \"neither - this just doesn't need to exist\".\n - Just ship two type aliases for `T | null` and `T | undefined` in `lib.d.ts`\n - We can sort of see that. It's not crazy.\n - We can't satisfy everyone - we're going to piss someone off.\n - But if we ship this without a `?` type modifier, it's the first thing we're going to hear, and we're going to hear it for the rest of our lives.\n- What's crazy about `T | null`?\n - You have an optional accessor that returns `number? | undefined`.\n - You end up with these awkward, funny-looking types.\n - Lack of symmetry between optional members and nullish types.\n - Becomes like the `const` modifier in C++.\n - Nobody understands where the heck to put `const` (before `*`, after `*`, at the end of a signature), and the differences are hard for people to grasp.\n - We understand it, but our users will get tripped up _a lot_.\n - People will definitely be confused about which to do.\n - Users on GitHub did not seem to be concerned with it - they understood very well.\n - Confirmation bias - these are people who are interested in language design to begin with.\n- Too many people are doing `null` to ignore that scenario.\n - Ultimately the question becomes is this disjoint or does it combine with the \"other\" use of `?` on optional parameters/properties.\n- @RyanCavanaugh: Extremely against `T?` meaning `T | null | undefined` because it muddies waters - So if we can't come to a conclusion, I think we should hold off on it.\n- We want to lead people to a pit of success, and we can't repeat the problem we have with modules. \n- Only consistency in discussion on thread is that there is no consistency. \n- We don't feel confident that we can do the \"right\" thing here out of the gate.\n- If people go out and fix type definitions and inappropriately use `?`, then you've made the ecosystem worse - we need to wary of this possibility.\n- @aleksey-bykov you get a :star:\n- Consensus: come back to this, since this is not a blocker for non-nullable types anyway.\n - Also, look into supplying type aliases in `lib.d.ts`.\n## Optional members on new members\n- Considering adding question marks on other members (https://github.com/Microsoft/TypeScript/issues/7426#issuecomment-195392211)\n - On local variable names (e.g. `let x?: number`).\n - On property declarations in classes (e.g. `class Foo { x?: number }`).\n - On call signatures (e.g. `function val(x?: string)?: number`).\n - On index signatures (e.g. `[x: string]?: Entity`).\n- We said it wasn't necessary because classes always have `undefined` by default, but non-nullable types make the world quite different.\n- Variables are more of a _questionable_ (pun intended) case - not entirely certain.\n - It seems like this would actually give you a case to say that your variable can be `undefined` and reflects that in the type.\n - Can we use that to model the dual of this on `?` in types?\n - Let's not go down that rabbit-hole.\n- Call signatures would have an awkward syntax.\n- Consensus: do it for properties, keep the rest this in mind, but come back to it.\n## Control-flow based type checking\n- We're going to need to do it.\n- We think we can do it with no significant perf hit.\n- Get perfect definite assignment errors.\n- Type guards should work perfectly.\n- We'll keep people posted.\n# UMD module support (#7264)\n- Idea with UMD modules is you write a declaration file.\n- In that same file, you write `export as namespace Foo` where `Foo` is some arbitrary identifier.\n- In a module, only if you use a `/// \u003creference path=\"...\" />`, is `Foo` visible.\n- In a script context, `Foo` is always visible if the `.d.ts` is in the compilation context.\n - Idea is that you're in a script/\"non-module\" context.\n- This is the new, better, way to write type definitions that need to be shared between old script-style code and modules.\n - The problem is that you always needed to duplicate your definitions across two different definition files, one which used an `export =`.\n- Problem: how do you reflect the type of the module itself?\n - Sometimes modules have members that refer to themselves.\n - We're still flexible here!\n - Continue using some value, use `export =`, and then use an `export namespace as Foo`.\n \n ``` ts\n interface jQueryStatic {\n foo: jQueryStatic\n }\n \n let jQuery: jQueryStatic;\n export = jQuery;\n export as namespace jQuery;\n ```\n- Why does `/// \u003creference path=\"...\" />` affect things? Why not just use a global module augmentation?\n - \n# Library include directives (#7263)\n- Answer to the question of \"How do we easily resolve types for script/global code?\"\n - Need to avoid situations where users have duplicate definitions due to \"global code\" being treated as conflicting even though they might refer to the same entities.\n- Syntax: `/// \u003creference library=\"jquery\" />`\n- What is the order of resolution for declaration files?\n - Take `/// \u003creference library=\"jquery\" />`.\n - Start from current module location.\n - Look for files walking up the spine of directories. For each directory:\n 1. If you see a file named `jquery.d.ts`, use that.\n 2. If you see a directory named `typings`, look in there.\n 3. If you see a directory named `node_modules`\n 1. Try to resolve in `node_modules/jquery/package.json` or use the `node_modules/jquery/index.d.ts`.\n 2. Try to resolve in `node_modules/jquery/package.json` or use the `node_modules/@types/jquery/index.d.ts` (or something similar).\n- Meeting cut short - may be more to the algorithm.\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2016-03-12T01:50:00Z","url":"https://github.com/microsoft/TypeScript/issues/7488"}
| 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:102824c7-23a2-b5f5-32a4-ade5bd1ec148 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B566:16EED3:13BD73B:1920269:6B0128AB |
| html-safe-nonce | c2a806a85c338e7f25f1fa100e98e035e730c8827c201b5089d864afe0f9af77 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTY2OjE2RUVEMzoxM0JENzNCOjE5MjAyNjk6NkIwMTI4QUIiLCJ2aXNpdG9yX2lkIjoiNjE5NTIxMzgwNzY5MDc4Njk4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e47472bac8d94f672aaa621958e28314e0db7c073ab26a54b203be34b9a6d0ea |
| hovercard-subject-tag | issue:140333724 |
| 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/7488/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ceda24ff3eeeb7b9c4cb182630e22855faa33ddf2c384c987ad231ee4e5426d2/microsoft/TypeScript/issues/7488 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ceda24ff3eeeb7b9c4cb182630e22855faa33ddf2c384c987ad231ee4e5426d2/microsoft/TypeScript/issues/7488 |
| og:image:alt | Non-nullable types (#7140) Question marks on types Let's start the bike-shedding! What does T? mean? function foo(x?: string) { // x: string | undefined } function foo(x: string?) { // ????? } func... |
| 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 | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width