Title: Function body is not checked against assertion signature · Issue #33743 · microsoft/TypeScript · GitHub
Open Graph Title: Function body is not checked against assertion signature · Issue #33743 · microsoft/TypeScript
X Title: Function body is not checked against assertion signature · Issue #33743 · microsoft/TypeScript
Description: TypeScript Version: 3.7.0-dev.20191002 Search Terms: assertion signatures, asserts, not checked, unchecked, unsound Code function assertIsString(x: number | string): asserts x is string { } function test(x: number | string) { assertIsStr...
Open Graph Description: TypeScript Version: 3.7.0-dev.20191002 Search Terms: assertion signatures, asserts, not checked, unchecked, unsound Code function assertIsString(x: number | string): asserts x is string { } functio...
X Description: TypeScript Version: 3.7.0-dev.20191002 Search Terms: assertion signatures, asserts, not checked, unchecked, unsound Code function assertIsString(x: number | string): asserts x is string { } functio...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33743
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function body is not checked against assertion signature","articleBody":"**TypeScript Version:** 3.7.0-dev.20191002\r\n\r\n**Search Terms:** assertion signatures, asserts, not checked, unchecked, unsound\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction assertIsString(x: number | string): asserts x is string {\r\n}\r\n\r\nfunction test(x: number | string) {\r\n assertIsString(x);\r\n x.toUpperCase();\r\n}\r\n\r\ntest(4);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThis incorrect empty implementation of `assertIsString` should not type check, because there are execution paths through `assertIsString` that don’t narrow the type of `x` to `string` as the type of `assertIsString` should require.\r\n\r\n**Actual behavior:**\r\n\r\nNo TS errors. Compiled JS code fails at runtime: `TypeError: x.toUpperCase is not a function`.\r\n\r\n**Playground Link:** Playground nightly isn’t new enough, but maybe it will be by the time you read this: [link](https://www.typescriptlang.org/play/?ts=Nightly#code/GYVwdgxgLglg9mABAQwM6oKYCcoElUDKUWMYA5gBQAeAXImCALYBG2iAPoqsaWQJR00mHKkRVEMUdxLlEAbwBQAXwULQkWAkRQM3anQYs2nabz7yFiKynTY8hHuWp8A3JetUAdFDgBVAA7+2ADCaBgUrsqqOnoALK5AA).\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/andersk","@type":"Person","name":"andersk"},"datePublished":"2019-10-02T07:30:25Z","url":"https://github.com/microsoft/TypeScript/issues/33743"}
| 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:1fda99db-d8ee-d005-5f1a-e7dca0e18be8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8086:117C62:BEAFDE:FFE37A:6B00F90F |
| html-safe-nonce | 2cc5411096abffd9b6b608b82a7eab31d2e0fd326d2370d9e4d494326823aa36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDg2OjExN0M2MjpCRUFGREU6RkZFMzdBOjZCMDBGOTBGIiwidmlzaXRvcl9pZCI6IjI1Mjc5ODU0NzEyNDY2MjkxMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f6670e6ff896c94b5ac8337d0782975f04578eada8621091ed351d3979d137fb |
| hovercard-subject-tag | issue:501324161 |
| 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/33743/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0400e66a024689b133ffe6a319f282bc3bbde8ebb709555801c396194b046625/microsoft/TypeScript/issues/33743 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0400e66a024689b133ffe6a319f282bc3bbde8ebb709555801c396194b046625/microsoft/TypeScript/issues/33743 |
| og:image:alt | TypeScript Version: 3.7.0-dev.20191002 Search Terms: assertion signatures, asserts, not checked, unchecked, unsound Code function assertIsString(x: number | string): asserts x is string { } functio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andersk |
| 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