Title: In Javascript, null/undefined initializers should be of type any, even with --strict · Issue #22458 · microsoft/TypeScript · GitHub
Open Graph Title: In Javascript, null/undefined initializers should be of type any, even with --strict · Issue #22458 · microsoft/TypeScript
X Title: In Javascript, null/undefined initializers should be of type any, even with --strict · Issue #22458 · microsoft/TypeScript
Description: In Typescript with --strict, an initializer of null or undefined has its respective type. Without a contextual type, the inferred type is just null or undefined. This is never desired, but it's easy to add a type annotation. This is not ...
Open Graph Description: In Typescript with --strict, an initializer of null or undefined has its respective type. Without a contextual type, the inferred type is just null or undefined. This is never desired, but it's eas...
X Description: In Typescript with --strict, an initializer of null or undefined has its respective type. Without a contextual type, the inferred type is just null or undefined. This is never desired, but it's...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22458
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"In Javascript, null/undefined initializers should be of type any, even with --strict","articleBody":"In Typescript with --strict, an initializer of `null` or `undefined` has its respective type. Without a contextual type, the inferred type is just `null` or `undefined`. This is never desired, but it's easy to add a type annotation. This is not true in Javascript.\r\n\r\n```ts\r\nfunction F(a = null) {\r\n a // should still be any; null | undefined is a nonsensical type\r\n this.b = null\r\n}\r\nvar f = new F('hi')\r\nf.b = 12\r\n\r\n// from async\r\nvar q = {\r\n drain: null,\r\n process() {\r\n if (q.drain) {\r\n q.drain()\r\n }\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nThe call to `new F('hi')`, the assignment `f.b = 12`, and the call `q.drain()` should all be allowed.\r\n\r\n**Actual behavior:**\r\nAssignability errors for the first two, \"Can't call null\" for the third.","author":{"url":"https://github.com/sandersn","@type":"Person","name":"sandersn"},"datePublished":"2018-03-10T15:46:36Z","url":"https://github.com/microsoft/TypeScript/issues/22458"}
| 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:fa985604-549f-8eed-e394-49301fdae5b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4EE:D1D28:107DEB9:15EE7CD:6B01E1F1 |
| html-safe-nonce | 75216a8ea185a3417320e8ba0efafcbb3a81019c735ca764d12ed919459a779c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEVFOkQxRDI4OjEwN0RFQjk6MTVFRTdDRDo2QjAxRTFGMSIsInZpc2l0b3JfaWQiOiI4MjM0ODE5MzMxODkzMDkyODQ5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 32ed58c51ef8138c49db0998fa2d490f31a90079fad8d42d494f58491b14e278 |
| hovercard-subject-tag | issue:304080181 |
| 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/22458/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e4485d1c1231c8fb7a5842abec90e9614175b22c99be1509e512007465941043/microsoft/TypeScript/issues/22458 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e4485d1c1231c8fb7a5842abec90e9614175b22c99be1509e512007465941043/microsoft/TypeScript/issues/22458 |
| og:image:alt | In Typescript with --strict, an initializer of null or undefined has its respective type. Without a contextual type, the inferred type is just null or undefined. This is never desired, but it's eas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sandersn |
| 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