Title: Confusing 'never' return type when appending an empty array · Issue #9976 · microsoft/TypeScript · GitHub
Open Graph Title: Confusing 'never' return type when appending an empty array · Issue #9976 · microsoft/TypeScript
X Title: Confusing 'never' return type when appending an empty array · Issue #9976 · microsoft/TypeScript
Description: TypeScript Version: 2.0.0 Code var x = []; x.push(1); Expected behavior: Accept this, and have the type inferencer postulate x:number[]. Alternatively, an error message along the lines of "cannot assign number to parameter {}" (because t...
Open Graph Description: TypeScript Version: 2.0.0 Code var x = []; x.push(1); Expected behavior: Accept this, and have the type inferencer postulate x:number[]. Alternatively, an error message along the lines of "cannot a...
X Description: TypeScript Version: 2.0.0 Code var x = []; x.push(1); Expected behavior: Accept this, and have the type inferencer postulate x:number[]. Alternatively, an error message along the lines of "can...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9976
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Confusing 'never' return type when appending an empty array","articleBody":"\u003c!-- BUGS: Please use this template. -->\n\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\n\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\n\n**TypeScript Version:** 2.0.0\n\n**Code**\n\n``` ts\n var x = [];\n x.push(1);\n```\n\n**Expected behavior:**\n Accept this, and have the type inferencer postulate `x:number[]`. Alternatively, an error message along the lines of \"cannot assign `number` to parameter `{}`\" (because type inferencer could also assume `x:undefined[]`).\n\n**Actual behavior:** \n(with `strictNullCheck`)\n\nerror TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.\n\nThis might be because of how `never` is documented as the \"bottom\" type (for functions that never return), but since the code isn't using the result expression, this is pretty confusing. Is this because the assumed type of `x` is `never[]`? \n\nI tried looking for related issues, I feel like it's slightly related to empty tuple discussions, but not 100% sure.\n","author":{"url":"https://github.com/rtpg","@type":"Person","name":"rtpg"},"datePublished":"2016-07-27T02:35:33Z","url":"https://github.com/microsoft/TypeScript/issues/9976"}
| 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:8bcad430-ba56-20a8-1d3a-dda863db8e98 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE06:A38CD:1EF547:2A38F9:6AFBFF3E |
| html-safe-nonce | 73f99f68302467b583085963e92610469563dc45d3110db6cb632acae9e3c5fd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTA2OkEzOENEOjFFRjU0NzoyQTM4Rjk6NkFGQkZGM0UiLCJ2aXNpdG9yX2lkIjoiNjYxNzU4OTAzNDgzNzA4MTkxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 69ed7a97691c4d807bf35855fbc6e18a474160a04474e6e36389a1b034328bb5 |
| hovercard-subject-tag | issue:167756013 |
| 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/9976/issue_layout |
| twitter:image | https://opengraph.githubassets.com/84d68bbf232015daf3854ac83b6c02a761421d6e424382c3e4c73093f7e53828/microsoft/TypeScript/issues/9976 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/84d68bbf232015daf3854ac83b6c02a761421d6e424382c3e4c73093f7e53828/microsoft/TypeScript/issues/9976 |
| og:image:alt | TypeScript Version: 2.0.0 Code var x = []; x.push(1); Expected behavior: Accept this, and have the type inferencer postulate x:number[]. Alternatively, an error message along the lines of "cannot a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rtpg |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width