Title: [Request for feedback] Nullable types, `null` and `undefined` · Issue #7426 · microsoft/TypeScript · GitHub
Open Graph Title: [Request for feedback] Nullable types, `null` and `undefined` · Issue #7426 · microsoft/TypeScript
X Title: [Request for feedback] Nullable types, `null` and `undefined` · Issue #7426 · microsoft/TypeScript
Description: With the work on Nullable types in #7140, we would like to field some user input on the current design proposal. First some background: null and undefined JavaScript has two ways that developers use today to denote uninitialized or no-va...
Open Graph Description: With the work on Nullable types in #7140, we would like to field some user input on the current design proposal. First some background: null and undefined JavaScript has two ways that developers us...
X Description: With the work on Nullable types in #7140, we would like to field some user input on the current design proposal. First some background: null and undefined JavaScript has two ways that developers us...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7426
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Request for feedback] Nullable types, `null` and `undefined`","articleBody":"With the work on Nullable types in https://github.com/Microsoft/TypeScript/pull/7140, we would like to field some user input on the current design proposal.\n\nFirst some background:\n## `null` and `undefined`\n\nJavaScript has two ways that developers use today to denote `uninitialized` or `no-value`. the two behave differently. where as null is completely left to user choice, there is no way of opting out of `undefined` , so:\n\n``` ts\nfunction foo(a?: number) {\n a // => number | undefined\n}\n\nfunction bar() {\n if(a) return 0;\n}\n\nbar() // => number | undefined\n```\n\n`a` will always implicitly has `undefined`, and so will the return type of `bar`.\n## Nullability\n\nGiven the JS semantics outlined above, what does a nullable type `T?` mean:\n1. `T | null | undefined`\n2. `T | undefined`\n#### 1. `T | null | undefined`\n\nIt is rather subtle what `?` means in different contexts:\n\n``` ts\nfunction bar(a: number?, b?: number) {\n a // => number | undefined | null\n b // => number | undefined\n}\n```\n#### 2. `T | undefined`\n\nThis is more consistent, the `?` always means to `| undefined`; no confusion here.\n\n`T??` can be used to mean `T | undefined | null` or `T? | null`\n","author":{"url":"https://github.com/mhegazy","@type":"Person","name":"mhegazy"},"datePublished":"2016-03-07T21:19:05Z","url":"https://github.com/microsoft/TypeScript/issues/7426"}
| 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:3c037173-9490-98dc-d396-d5c2c40054e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C996:311EEE:1AA751B:234A6E7:6B014F13 |
| html-safe-nonce | 1429061f5a1df1da1926a324413a5e3f1fabb51e71b3a80c37f58b117435a7b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTk2OjMxMUVFRToxQUE3NTFCOjIzNEE2RTc6NkIwMTRGMTMiLCJ2aXNpdG9yX2lkIjoiNTI5OTU1NTIwNDgyMjI5MDE5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6df96f411a273c9fc3e905e65d737722c268c0e8e4eb6bcb2cbfc0ce1e4e7127 |
| hovercard-subject-tag | issue:139097459 |
| 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/7426/issue_layout |
| twitter:image | https://opengraph.githubassets.com/371ecf9132ba0e1f1152ada78ef7db800b9f75be838b0a0c440eaf871a0a54a6/microsoft/TypeScript/issues/7426 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/371ecf9132ba0e1f1152ada78ef7db800b9f75be838b0a0c440eaf871a0a54a6/microsoft/TypeScript/issues/7426 |
| og:image:alt | With the work on Nullable types in #7140, we would like to field some user input on the current design proposal. First some background: null and undefined JavaScript has two ways that developers us... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhegazy |
| 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