Title: Allow comparing anything with null or undefined even when strict null checks are enabled · Issue #8439 · microsoft/TypeScript · GitHub
Open Graph Title: Allow comparing anything with null or undefined even when strict null checks are enabled · Issue #8439 · microsoft/TypeScript
X Title: Allow comparing anything with null or undefined even when strict null checks are enabled · Issue #8439 · microsoft/TypeScript
Description: TypeScript Version: 1.9.0-dev.20160503 Code: export function safeLibraryFunction1(arg: string) { if (arg == null) throw new TypeError(`Hi JS Consumer, I checked, it turns out the argument you gave was a null or undefined`); if (typeof ar...
Open Graph Description: TypeScript Version: 1.9.0-dev.20160503 Code: export function safeLibraryFunction1(arg: string) { if (arg == null) throw new TypeError(`Hi JS Consumer, I checked, it turns out the argument you gave ...
X Description: TypeScript Version: 1.9.0-dev.20160503 Code: export function safeLibraryFunction1(arg: string) { if (arg == null) throw new TypeError(`Hi JS Consumer, I checked, it turns out the argument you gave ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/8439
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow comparing anything with null or undefined even when strict null checks are enabled","articleBody":"**TypeScript Version:** \n\n1.9.0-dev.20160503\n\n**Code:**\n\n``` ts\nexport function safeLibraryFunction1(arg: string) {\n if (arg == null)\n throw new TypeError(`Hi JS Consumer, I checked, it turns out the argument you \n gave was a null or undefined`);\n\n if (typeof arg !== \"string\")\n throw new TypeError(`Hi JS Consumer, I checked, the argument you gave me wasn't a string.. \n seems like something went wrong in your program?..`);\n // ..\n}\n\ninterface SomeType {\n a: number;\n}\n\nexport function safeLibraryFunction2(arg: SomeType) {\n if (arg === undefined)\n throw new TypeError(`Hi TS Consumer, it turns out the argument was undefined.\n I don't assume you're using strict nullability checks,\n I know that could be a bit difficult thing to introduce\n or you haven't even heard about it \n so I also check at runtime :)`);\n if (arg === null)\n throw new TypeError(`Hi TS Consumer, it turns out the argument was null, \n maybe you had an unsafe cast somewhere in your program\n or you're not using strict nullability checks?\n I already thought of that so I checked anyway ;)`);\n // ..\n}\n\nexport function safeLibraryFunction3(arg: SomeType) {\n if (arg != null) {\n //.. do something\n }\n else {\n throw new TypeError(`Hi JS Consumer, I think about you all the time\n that's why I put many safeguards in my program\n to make sure that everything goes smoothly..\n c'ya later..`);\n }\n\n}\n```\n\n**Expected behavior:**\nThe comparisons work.\n\n**Actual behavior:** \n\n```\nOperator `==` cannot be applied to type X and null\n```\n\n```\nOperator `===` cannot be applied to type X and null\n```\n\n```\nOperator `===` cannot be applied to type X and undefined\n```\n\n```\nOperator `!=` cannot be applied to type X and null\n```\n\n(My projects are full of these errors when `strictNullChecks` is enabled)\n","author":{"url":"https://github.com/malibuzios","@type":"Person","name":"malibuzios"},"datePublished":"2016-05-03T14:22:12Z","url":"https://github.com/microsoft/TypeScript/issues/8439"}
| 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:ab16d575-29db-5f3a-ad31-a0bcca0e5c0e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E210:3A8E64:A3420C:D8817F:6B01BBAD |
| html-safe-nonce | 092ee26b0097018662274306312f2ecae89307eca37c90e0fc81f668f871ade7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjEwOjNBOEU2NDpBMzQyMEM6RDg4MTdGOjZCMDFCQkFEIiwidmlzaXRvcl9pZCI6IjY1NzA4NzQ0NzUxNTAxNjI4NjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8840fc0f5bff15795f10483811ced0dfed4fe5f6ebe4a90c6970bb19e8689447 |
| hovercard-subject-tag | issue:152785912 |
| 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/8439/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0e0799d1a41be3bc91ac7e44ff0908e280fd2270e07ba5625598ec60d66e5505/microsoft/TypeScript/issues/8439 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0e0799d1a41be3bc91ac7e44ff0908e280fd2270e07ba5625598ec60d66e5505/microsoft/TypeScript/issues/8439 |
| og:image:alt | TypeScript Version: 1.9.0-dev.20160503 Code: export function safeLibraryFunction1(arg: string) { if (arg == null) throw new TypeError(`Hi JS Consumer, I checked, it turns out the argument you gave ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | malibuzios |
| 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