{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7426","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7426/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7426/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7426/events","html_url":"https://github.com/Microsoft/TypeScript/issues/7426","id":139097459,"number":7426,"title":"[Request for feedback] Nullable types, `null` and `undefined`","user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Discussion","name":"Discussion","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-03-07T21:19:05Z","updated_at":"2016-03-08T02:43:30Z","closed_at":null,"body":"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.\r\n\r\n\r\nFirst some background:\r\n\r\n## `null` and `undefined`\r\n\r\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:\r\n\r\n```ts\r\nfunction foo(a?: number) {\r\n   a // => number | undefined\r\n}\r\n\r\nfunction bar() {\r\n    if(a) return 0;\r\n}\r\n\r\nbar() // => number | undefined\r\n```\r\n`a` will always implicitly has `undefined`, and so will the return type of `bar`.\r\n\r\n## Nullability\r\n\r\nGiven the JS semantics outlined above, what does a nullable type `T?` mean:\r\n 1.  `T | null | undefined`\r\n 2.  `T | undefined`\r\n\r\n####  1.  `T | null | undefined`\r\n\r\nIt is rather subtle what `?` means in different contexts:\r\n\r\n```ts\r\nfunction bar(a: number?, b?: number) {\r\n  a // => number | undefined | null\r\n  b // => number | undefined\r\n}\r\n```\r\n\r\n#### 2.  `T | undefined`\r\n\r\nThis is more consistent, the `?` always means to `| undefined`; no confusion here.\r\n\r\n`T??` can be used to mean `T | undefined | null` or `T? | null`\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/193569235","html_url":"https://github.com/Microsoft/TypeScript/issues/7426#issuecomment-193569235","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7426","id":193569235,"user":{"login":"EmmanuelOga","id":13634,"avatar_url":"https://avatars.githubusercontent.com/u/13634?v=3","gravatar_id":"","url":"https://api.github.com/users/EmmanuelOga","html_url":"https://github.com/EmmanuelOga","followers_url":"https://api.github.com/users/EmmanuelOga/followers","following_url":"https://api.github.com/users/EmmanuelOga/following{/other_user}","gists_url":"https://api.github.com/users/EmmanuelOga/gists{/gist_id}","starred_url":"https://api.github.com/users/EmmanuelOga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EmmanuelOga/subscriptions","organizations_url":"https://api.github.com/users/EmmanuelOga/orgs","repos_url":"https://api.github.com/users/EmmanuelOga/repos","events_url":"https://api.github.com/users/EmmanuelOga/events{/privacy}","received_events_url":"https://api.github.com/users/EmmanuelOga/received_events","type":"User","site_admin":false},"created_at":"2016-03-08T02:43:30Z","updated_at":"2016-03-08T02:43:30Z","body":"In case someone finds this useful there's a [similar proposal for the dart language here](https://github.com/chalin/DEP-non-null/blob/master/doc/dep-non-null-AUTOGENERATED-DO-NOT-EDIT.md#precedent) (Non-null Types and Non-null By Default (NNBD)). \r\n\r\nIt includes a comparison to null types in other languages."}}