Title: #27370 breaks narrowing for constructor functions · Issue #27550 · microsoft/TypeScript · GitHub
Open Graph Title: #27370 breaks narrowing for constructor functions · Issue #27550 · microsoft/TypeScript
X Title: #27370 breaks narrowing for constructor functions · Issue #27550 · microsoft/TypeScript
Description: Based on code from uglify: /** @constructor */ function AtTop(val) { this.val = val } /** @type {*} */ var x = 1; if (x instanceof AtTop) { x.val } Expected behavior: x doesn't narrow inside the if and x: any and x.val: any. Actual behav...
Open Graph Description: Based on code from uglify: /** @constructor */ function AtTop(val) { this.val = val } /** @type {*} */ var x = 1; if (x instanceof AtTop) { x.val } Expected behavior: x doesn't narrow inside the if...
X Description: Based on code from uglify: /** @constructor */ function AtTop(val) { this.val = val } /** @type {*} */ var x = 1; if (x instanceof AtTop) { x.val } Expected behavior: x doesn't narrow inside th...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27550
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"#27370 breaks narrowing for constructor functions","articleBody":"Based on code from uglify:\r\n\r\n```js\r\n/** @constructor */\r\nfunction AtTop(val) { this.val = val }\r\n/** @type {*} */\r\nvar x = 1;\r\nif (x instanceof AtTop) {\r\n x.val\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n`x` doesn't narrow inside the if and `x: any` and `x.val: any`.\r\n\r\n**Actual behavior:**\r\n`x` narrows to `x: {}` and gives an error on `x.val`.\r\n\r\nI think the reason is that constructor functions are special-cased in resolveCallExpression -- they still only have call signatures, not construct signatures. The code in narrowTypeByInstanceof probably needs the same special-casing (or to have it in one place).","author":{"url":"https://github.com/sandersn","@type":"Person","name":"sandersn"},"datePublished":"2018-10-04T15:47:32Z","url":"https://github.com/microsoft/TypeScript/issues/27550"}
| 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:17270685-da02-450b-f98d-2cd632d0f622 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA20:3A4875:24FFC91:31512E3:6B019EA4 |
| html-safe-nonce | 873860ee2c75c6e5324b70e7f56db424ab197c277d1c056629e6641bf2bf8b3c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTIwOjNBNDg3NToyNEZGQzkxOjMxNTEyRTM6NkIwMTlFQTQiLCJ2aXNpdG9yX2lkIjoiMzMxNDE5NDU2MzUxNzc1MDk0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e8dfc587870eadb88bf27039515575653584e07f47c1fddba5a43af88e58a95d |
| hovercard-subject-tag | issue:366854993 |
| 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/27550/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e252f0b125559d1c9013f4123b31ac5c824d577045c8930fb1fcf14e747a3fed/microsoft/TypeScript/issues/27550 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e252f0b125559d1c9013f4123b31ac5c824d577045c8930fb1fcf14e747a3fed/microsoft/TypeScript/issues/27550 |
| og:image:alt | Based on code from uglify: /** @constructor */ function AtTop(val) { this.val = val } /** @type {*} */ var x = 1; if (x instanceof AtTop) { x.val } Expected behavior: x doesn't narrow inside the if... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sandersn |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width