Title: typescript passes `number | Promise
Open Graph Title: typescript passes `number | Promise
X Title: typescript passes `number | Promise
Description: Bug Report Something is very weird that makes typescript pass Promise
Open Graph Description: Bug Report Something is very weird that makes typescript pass Promise
X Description: Bug Report Something is very weird that makes typescript pass Promise<number> as if it were a number when it is an object field. Typescript correctly recognizes that Promise<number> is ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52036
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"typescript passes `number | Promise\u003cnumber\u003e` as if it were `number` (or something like that)","articleBody":"# Bug Report\r\n\r\nSomething is very weird that makes typescript pass `Promise\u003cnumber\u003e` as if it were a `number` when it is an object field. Typescript correctly recognizes that `Promise\u003cnumber\u003e` is not a number when it is a plain variable. Weird.\r\n\r\n### 🔎 Search Terms\r\n\r\npromise numeric\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\nI believe this has always existed in typescript. I have tried multiple versions on playground (from 3.3 up to 5). I did read the FAQs in https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs and found nothing related.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.0-dev.20221227#code/MYewdgzgLgBGBccCuBbARgUwE4wD4wAUsQUBLCDAHjFUywD4YBeQ4sigOiwwhABsAbhgAUABgCUAbgBQoSPwwc+IAObCwMeiwmSYMAPT6YAYRBZuwKHwCeMbgCsMljABNEAeQAO2AIZQzmizAPmBgILCYMD6ennykrjD+rCTkVDTo2IwhLsgZWBzSsuDQMABmICCIAN4IuXR4yexptJkAvswwVdJ6tUQpnNy8giISADTSrTJyQ4rKauUgHBpaMDoGRgCSYKDmTla2UNbeMMAAFk4A1hAcegBKSGBQpCgYdjxIfLDkMGiqSNfSIA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nconst n: number | Promise\u003cnumber\u003e = Promise.resolve(0);\r\nconsole.log(n \u003e= 0); // Correctly rejected: Operator \u003e= cannot be applied to Promise\u003cnumber\u003e and number.\r\n\r\nconst foo: {n: number | Promise\u003cnumber\u003e} = {\r\n n: Promise.resolve(0),\r\n};\r\nconsole.log(foo.n \u003e= 0); // Incorrectly type checks. Runtime result is bogus.\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe last expression passes the type checker even though it is clearly wrong.\r\n\r\n### 🙂 Expected behavior\r\n\r\nThat the last expression is rejected with `Operator \u003e= cannot be applied to Promise\u003cnumber\u003e and number.`.","author":{"url":"https://github.com/azizghuloum","@type":"Person","name":"azizghuloum"},"datePublished":"2022-12-28T00:51:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/52036/TypeScript/issues/52036"}
| 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:41c8b845-63d7-3b33-3d7d-13f31ec0feba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ECC8:17CBFE:985309:CD5DC7:6A62B413 |
| html-safe-nonce | 27678ca2f0945c4cfd272a2b373a91274706ed37ebb908dcbbddbce9a9f2ecaf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQ0M4OjE3Q0JGRTo5ODUzMDk6Q0Q1REM3OjZBNjJCNDEzIiwidmlzaXRvcl9pZCI6IjM1NDAxMzMwOTE5MzQ5MDk0NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 55caa28b40ca79687d77e05ca9e0fa49e225c8087ab95a4153a15e1b648b5822 |
| hovercard-subject-tag | issue:1512294916 |
| 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/52036/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d779154f46d234c736a74f7df729add020b701f2235e3021e1d014568aeb9c0a/microsoft/TypeScript/issues/52036 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d779154f46d234c736a74f7df729add020b701f2235e3021e1d014568aeb9c0a/microsoft/TypeScript/issues/52036 |
| og:image:alt | Bug Report Something is very weird that makes typescript pass Promise |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | azizghuloum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2738d7125e864b55224a8bc40c72c220ca7d2c73f91a7bb8d69dffe9d35e997d |
| 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 | bf54af498459157b66a67136f992a68752cdbb54 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width