Title: non-null assertion not working on type parameter with constraint · Issue #20974 · microsoft/TypeScript · GitHub
Open Graph Title: non-null assertion not working on type parameter with constraint · Issue #20974 · microsoft/TypeScript
X Title: non-null assertion not working on type parameter with constraint · Issue #20974 · microsoft/TypeScript
Description: TypeScript Version: 2.7.0-dev.20171230 Code function takeString(p: string) {} function foo
Open Graph Description: TypeScript Version: 2.7.0-dev.20171230 Code function takeString(p: string) {} function foo
X Description: TypeScript Version: 2.7.0-dev.20171230 Code function takeString(p: string) {} function foo<T extends string | undefined>(param: T) { takeString(param!); // error on this line } Expected behav...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20974
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"non-null assertion not working on type parameter with constraint","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.7.0-dev.20171230\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction takeString(p: string) {}\r\n\r\nfunction foo\u003cT extends string | undefined>(param: T) {\r\n takeString(param!); // error on this line\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nBecause of the constraint the compiler knows the type of `param` can only be `string | undefined`. Asserting the type with a non-null assertion should result in `string` and the code should compile without error.\r\n\r\nIf this is working as intended, I'll write a lint rule to warn about non-null assertions on type parameters.\r\n\r\n**Actual behavior:**\r\n```\r\nArgument of type 'T' is not assignable to parameter of type 'string'.\r\n Type 'string | undefined' is not assignable to type 'string'.\r\n Type 'undefined' is not assignable to type 'string'.\r\n```","author":{"url":"https://github.com/ajafff","@type":"Person","name":"ajafff"},"datePublished":"2018-01-02T21:31:29Z","url":"https://github.com/microsoft/TypeScript/issues/20974"}
| 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:cd297f75-3cda-722e-e0b8-c0a85f7ab133 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 821C:FC5BE:C17A9B:101E955:6B00F8C3 |
| html-safe-nonce | 6070bc2f8b0be07aea5a0947ee394bc8c12b9fc6efa061564d650b59b9ca07b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjFDOkZDNUJFOkMxN0E5QjoxMDFFOTU1OjZCMDBGOEMzIiwidmlzaXRvcl9pZCI6IjMyNDYwMDM5MTc1MTQ5MzAzNzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 99c93079c6d740499db605ea6673c59d40387d6a7d1d5b921d9a32f63154d190 |
| hovercard-subject-tag | issue:285542669 |
| 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/20974/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1a43983994ee90a895a3c7531b53d7f8a5ed9ce11915b9e7e07ae16492107ac9/microsoft/TypeScript/issues/20974 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1a43983994ee90a895a3c7531b53d7f8a5ed9ce11915b9e7e07ae16492107ac9/microsoft/TypeScript/issues/20974 |
| og:image:alt | TypeScript Version: 2.7.0-dev.20171230 Code function takeString(p: string) {} function foo |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ajafff |
| 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