Title: Legitimate type assertion causes compiler error · Issue #7598 · microsoft/TypeScript · GitHub
Open Graph Title: Legitimate type assertion causes compiler error · Issue #7598 · microsoft/TypeScript
X Title: Legitimate type assertion causes compiler error · Issue #7598 · microsoft/TypeScript
Description: Typscript version Nuget package manager in Visual Studio reports it as v2.0.0 "tsc --v" reports it as v1.0.0.0 Code class Animal { public speak() { if (this instanceof Dog) { var dog: Dog =
Open Graph Description: Typscript version Nuget package manager in Visual Studio reports it as v2.0.0 "tsc --v" reports it as v1.0.0.0 Code class Animal { public speak() { if (this instanceof Dog) { var dog: Dog =
X Description: Typscript version Nuget package manager in Visual Studio reports it as v2.0.0 "tsc --v" reports it as v1.0.0.0 Code class Animal { public speak() { if (this instanceof Dog) { var dog: Dog...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7598
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Legitimate type assertion causes compiler error","articleBody":"**Typscript version**\n Nuget package manager in Visual Studio reports it as v2.0.0\n \"tsc --v\" reports it as v1.0.0.0\n\n**Code**\n\n```\nclass Animal {\n\n public speak() {\n if (this instanceof Dog) {\n var dog: Dog = \u003cDog>this;\n dog.woof();\n }\n }\n}\n\nclass Dog extends Animal {\n public woof() {}\n}\n```\n\n**Expected behavior:**\n\nShould compile without issue. I expect to be able to assert that \"this\" is of type Dog, because it can be. I also note that \"woof\" is referred to as a property in the error message, when perhaps it should be referred to as a method.\n\nObviously in this case, it would make sense to override Animal.speak() in Dog rather than check the type in Animal.speak(), but sometimes it makes sense to check the type of \"this\" explicitly, perhaps because you want to perform some action in the middle of a method in the base class, between various other actions, and overriding doesn't make that possible.\n\nIn any case, good practice or bad practice, it's valid code and should compile.\n\n**Actual behavior:** \n\nError TS2352 Neither type 'this' nor type 'Dog' is assignable to the other.\n Type 'Animal' is not assignable to type 'Dog'.\n Property 'woof' is missing in type 'Animal'.\n","author":{"url":"https://github.com/philthy256","@type":"Person","name":"philthy256"},"datePublished":"2016-03-20T09:39:06Z","url":"https://github.com/microsoft/TypeScript/issues/7598"}
| 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:aa8b55be-4c96-26dc-7e3a-3ad60b0ce9c9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFD6:187C1E:CE0445:110B474:6B01C9B8 |
| html-safe-nonce | 90d8e2cd06e04e83eecd7bd13e8c4c23fac1071cab55a970139ff03eac9429a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkQ2OjE4N0MxRTpDRTA0NDU6MTEwQjQ3NDo2QjAxQzlCOCIsInZpc2l0b3JfaWQiOiI1Njk4NTkzMTM0NDYwNjUxOTYwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2eb999940c1f7981a402dfc004475a53e9ae717bad4169aee49da4c4ae8ed3fc |
| hovercard-subject-tag | issue:142145548 |
| 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/7598/issue_layout |
| twitter:image | https://opengraph.githubassets.com/71b81b5817692b27dda01ec423e832266f8135d4da19567deebc6a8c03177712/microsoft/TypeScript/issues/7598 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/71b81b5817692b27dda01ec423e832266f8135d4da19567deebc6a8c03177712/microsoft/TypeScript/issues/7598 |
| og:image:alt | Typscript version Nuget package manager in Visual Studio reports it as v2.0.0 "tsc --v" reports it as v1.0.0.0 Code class Animal { public speak() { if (this instanceof Dog) { var dog: Dog = |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | philthy256 |
| 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