Title: Issue · GitHub
Open Graph Title: Issue · microsoft/TypeScript
X Title: Issue · microsoft/TypeScript
Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Issue · microsoft/TypeScript
Open Graph Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Issue · microsoft/TypeScript
X Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Issue · microsoft/TypeScript
Opengraph URL: https://github.com/microsoft/TypeScript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optional local variables","articleBody":"## Suggestion\r\n\r\nTypeScript already supports optional parameters and fields with a question mark.\r\nWhy not extend this feature to local variables as well, to allow them having an undefined value, e.g.\r\n\r\n## Use Cases/Examples\r\n\r\n```\r\nlet optional?: number = 123\r\noptional = undefined // allowed\r\n```\r\n\r\nin this case specifying `number` type is also optional:\r\n\r\n```\r\nlet optional? = 123\r\n```\r\n\r\nThis would complete the usage of question mark `?` as nullablity/unefineability operator, similar to Kotlin.\r\n\r\nCurrently, defining an optional variable requires writing a lot of noise, e.g.\r\n\r\n```\r\nlet optional: number|undefined = undefined // too verbose\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n","author":{"url":"https://github.com/angryziber","@type":"Person","name":"angryziber"},"datePublished":"2020-12-09T19:31:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/41901/TypeScript/issues/41901"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:2997337e-784a-6264-7d99-525a170b5bf4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B1C:BD584:503A27:742681:6A61EBCD |
| html-safe-nonce | ae7e123f92848f7e39637d7718e17a233bad885b1d3e4fc31682eb3d1c8412d8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjFDOkJENTg0OjUwM0EyNzo3NDI2ODE6NkE2MUVCQ0QiLCJ2aXNpdG9yX2lkIjoiODc4OTk5MDYxNDE5OTU2MTE2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 18c4d11ff2b9f8c47881bbda8dcf4e5c19bdd15e031395e78aa437faa93c46c5 |
| hovercard-subject-tag | repository:20929025 |
| 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/microsoft/TypeScript/issues/41901 |
| twitter:image | https://opengraph.githubassets.com/c6b83119f073c2cb800cf5f99488ccc1fc43230c90795e7dceb17b8cc1bd7308/microsoft/TypeScript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c6b83119f073c2cb800cf5f99488ccc1fc43230c90795e7dceb17b8cc1bd7308/microsoft/TypeScript |
| og:image:alt | TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Issue · microsoft/TypeScript |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5dd1217fff37e297563b9d318ee02bf6378c8957c6195b77786bb8896fc9c95d |
| turbo-cache-control | no-cache |
| 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 | 554667f6dda2a53c83687de64fabc457970f0f04 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width