Title: Weird checking errors when using async function, and generic typings · Issue #15702 · microsoft/TypeScript · GitHub
Open Graph Title: Weird checking errors when using async function, and generic typings · Issue #15702 · microsoft/TypeScript
X Title: Weird checking errors when using async function, and generic typings · Issue #15702 · microsoft/TypeScript
Description: It feels to me like this could be a compiler issue: I'm trying to get the compiler to check the type of a promise, but I get a strange behavior. The following code show 4 different return options I tried: TypeScript Version: 2.3.2 Code i...
Open Graph Description: It feels to me like this could be a compiler issue: I'm trying to get the compiler to check the type of a promise, but I get a strange behavior. The following code show 4 different return options I...
X Description: It feels to me like this could be a compiler issue: I'm trying to get the compiler to check the type of a promise, but I get a strange behavior. The following code show 4 different return optio...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15702
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Weird checking errors when using async function, and generic typings","articleBody":"It feels to me like this could be a compiler issue:\r\n\r\nI'm trying to get the compiler to check the type of a promise, but I get a strange behavior. The following code show 4 different `return` options I tried:\r\n\r\n**TypeScript Version:** 2.3.2 \r\n\r\n**Code**\r\n\r\n```ts\r\ninterface MyResponse\u003cT> {\r\n foo: number,\r\n data: T,\r\n}\r\n\r\nconst g: () => Promise\u003cMyResponse\u003cnumber>> = async () => {\r\n\r\n // This looks perfectly fine to me:\r\n // ERROR: Type 'string' is not assignable to type 'number'.\r\n return {\r\n foo: 1,\r\n data: 'wrong type'\r\n }\r\n\r\n // Both foo and data are missing, but I get no error. I don't get why\r\n return {}\r\n\r\n // data is missing, but still no error\r\n return {\r\n foo: 1\r\n }\r\n\r\n // Now the compiler complains about `data` being missing\r\n // ERROR: Property 'data' is missing in type '{ foo: number; bar: string; }'.\r\n return {\r\n foo: 1,\r\n bar: 'this fails'\r\n }\r\n\r\n}\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n- I would expect the compiler to warn me about missing properties if I return an empty or partially filled object\r\n\r\n**Actual behavior:**\r\n\r\nAs described in the code comments\r\n\r\nIf this is of any relevance, here is my compiler options:\r\n\r\n```ts\r\n \"compilerOptions\": {\r\n \"experimentalDecorators\": true,\r\n \"module\": \"commonjs\",\r\n \"outDir\": \"./dist/\",\r\n \"sourceMap\": true,\r\n \"strictNullChecks\": true,\r\n \"target\": \"es6\"\r\n },\r\n```\r\n","author":{"url":"https://github.com/aherve","@type":"Person","name":"aherve"},"datePublished":"2017-05-09T15:42:35Z","url":"https://github.com/microsoft/TypeScript/issues/15702"}
| 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:f7dc3517-5b99-5632-c1fd-0a10a9df1bd8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE58:22DB35:D0BC89:10D6914:6B00F214 |
| html-safe-nonce | 9fb57044082fd72a05ff8bc259668bf6deb8e8a7ced443c0d0bc7d59127461b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTU4OjIyREIzNTpEMEJDODk6MTBENjkxNDo2QjAwRjIxNCIsInZpc2l0b3JfaWQiOiI3NzU4OTE3MDU2OTEyNzQ5MDc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b5b814c92a40f45a53c67488ae2fa108e55d0e3139c013fb42b5e916b9f11124 |
| hovercard-subject-tag | issue:227409906 |
| 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/15702/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2cc6262f8efdd34a15e80f0e9d70c5da61b2051b3137300bfce1792bef20ec7b/microsoft/TypeScript/issues/15702 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2cc6262f8efdd34a15e80f0e9d70c5da61b2051b3137300bfce1792bef20ec7b/microsoft/TypeScript/issues/15702 |
| og:image:alt | It feels to me like this could be a compiler issue: I'm trying to get the compiler to check the type of a promise, but I get a strange behavior. The following code show 4 different return options I... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aherve |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width