Title: NonNullable not properly casting generic type when excluding nullish values · Issue #48048 · microsoft/TypeScript · GitHub
Open Graph Title: NonNullable not properly casting generic type when excluding nullish values · Issue #48048 · microsoft/TypeScript
X Title: NonNullable not properly casting generic type when excluding nullish values · Issue #48048 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms Generic types nonnullable 🕗 Version & Regression Information This bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4) ⏯ Playground Link Playground link with relevant code 💻 Co...
Open Graph Description: Bug Report 🔎 Search Terms Generic types nonnullable 🕗 Version & Regression Information This bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4) ⏯ Playground Link...
X Description: Bug Report 🔎 Search Terms Generic types nonnullable 🕗 Version & Regression Information This bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4) ⏯ Playground ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48048
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NonNullable not properly casting generic type when excluding nullish values","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nGeneric types nonnullable\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nThis bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4)\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABFAFgJzgdwJLAHIgA2hAhgEaECmAPACoB8AFALABQiiAbiYSJQFyJaAGjYBKQXgQFi5KnXqIA3mw4xgiRt16VEAQgC8BxOAAmlYDDCVTAAoBk9rjz76jiMEUJjlqjojRKKBA0JG0+AG4-AF82P1QMTEQAUTQMNEYAchlSCkpMsTZY1iA)\r\n\r\n### 💻 Code\r\n\r\n```typescript\r\nfunction throwIfNullable\u003cT>(\r\n value: T,\r\n): NonNullable\u003cT> {\r\n if (value !== undefined && value !== null) {\r\n return value;\r\n }\r\n\r\n throw Error('Nullable')\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe line `return value` raises a compilation error `Type 'T' is not assignable to type 'NonNullable\u003cT>'.`\r\n\r\n### 🙂 Expected behavior\r\n\r\nNo compilation error as the if clause properly guards against nullish values\r\n","author":{"url":"https://github.com/flavianh","@type":"Person","name":"flavianh"},"datePublished":"2022-02-26T21:40:04Z","url":"https://github.com/microsoft/TypeScript/issues/48048"}
| 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:164153af-bad9-6403-2b33-fa0d48023e1d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABD6:33444D:C1853B:102B252:6B00F8B9 |
| html-safe-nonce | 6d6d95b6ca75ded5d8080b47a585e62dda07812b456c093b8e990d95777768bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkQ2OjMzNDQ0RDpDMTg1M0I6MTAyQjI1Mjo2QjAwRjhCOSIsInZpc2l0b3JfaWQiOiIyMDU1NDQ2NjAyMzM1NzEzNDY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3441bf9f1c29906d71ce4396faeef836cb6b2915a15cbf5be77b6702f6e0ff87 |
| hovercard-subject-tag | issue:1152343675 |
| 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/48048/issue_layout |
| twitter:image | https://opengraph.githubassets.com/098e3525c266576b236651a8ff2aef6cd2b243d74df22e6223748f8031d9efed/microsoft/TypeScript/issues/48048 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/098e3525c266576b236651a8ff2aef6cd2b243d74df22e6223748f8031d9efed/microsoft/TypeScript/issues/48048 |
| og:image:alt | Bug Report 🔎 Search Terms Generic types nonnullable 🕗 Version & Regression Information This bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4) ⏯ Playground Link... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | flavianh |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width