Title: Extending global Function interface breaks instanceof Type Guard · Issue #26159 · microsoft/TypeScript · GitHub
Open Graph Title: Extending global Function interface breaks instanceof Type Guard · Issue #26159 · microsoft/TypeScript
X Title: Extending global Function interface breaks instanceof Type Guard · Issue #26159 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: global Function interface instanceof Type Guard Code declare global { interface Function { now(): string; } } Function.prototype.now = function () { return "now" } class X { static now...
Open Graph Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: global Function interface instanceof Type Guard Code declare global { interface Function { now(): string; } } Function.prototype.now = function ...
X Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: global Function interface instanceof Type Guard Code declare global { interface Function { now(): string; } } Function.prototype.now = function ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26159
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Extending global Function interface breaks instanceof Type Guard","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.1.0-dev.201xxxxx\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\nglobal Function interface\r\ninstanceof\r\nType Guard\r\n\r\n**Code**\r\n\r\n```ts\r\ndeclare global {\r\n interface Function {\r\n now(): string;\r\n }\r\n}\r\n\r\nFunction.prototype.now = function () {\r\n return \"now\"\r\n}\r\n\r\nclass X {\r\n static now() {\r\n return {}\r\n }\r\n\r\n why() {\r\n\r\n }\r\n}\r\n\r\nclass Y {\r\n\r\n}\r\n\r\nconsole.log(X.now()) // works as expected\r\nconsole.log(Y.now()) // works as expected\r\n\r\nexport const x: X | number = Math.random() > 0.5 ? new X() : 1\r\n\r\nif (x instanceof X) {\r\n x.why() // should compile\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nCode compiles\r\n\r\n**Actual behavior:**\r\nCompilation failed \r\n\"Property 'why' does not exist on type 'number'.\"\r\n\r\n**Playground Link:** [Playground](https://www.typescriptlang.org/play/#src=declare%20global%20%7B%0A%20%20interface%20Function%20%7B%0A%20%20%20%20now()%3A%20string%3B%0A%20%20%7D%0A%7D%0A%0AFunction.prototype.now%20%3D%20function%20()%20%7B%0A%20%20return%20%22now%22%0A%7D%0A%0Aclass%20X%20%7B%0A%20%20static%20now()%20%7B%0A%20%20%20%20return%20%7B%7D%0A%20%20%7D%0A%0A%20%20why()%20%7B%0A%0A%20%20%7D%0A%7D%0A%0Aclass%20Y%20%7B%0A%0A%7D%0A%0Aconsole.log(X.now())%20%2F%2F%20works%20as%20expected%0Aconsole.log(Y.now())%20%2F%2F%20works%20as%20expected%0A%0Aexport%20const%20x%3A%20X%20%7C%20number%20%3D%20Math.random()%20%3E%200.5%20%3F%20new%20X()%20%3A%201%0A%0Aif%20(x%20instanceof%20X)%20%7B%0A%20%20x.why()%20%2F%2F%20should%20compile%0A%7D%0A)\r\n\r\n**Related Issues:** \r\nhttps://github.com/Microsoft/TypeScript/issues/7271\r\n","author":{"url":"https://github.com/kobiburnley","@type":"Person","name":"kobiburnley"},"datePublished":"2018-08-02T15:13:20Z","url":"https://github.com/microsoft/TypeScript/issues/26159"}
| 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:f4f0c260-bfa5-a756-178d-a290e92b02cc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABFA:22DB35:2E1ABB2:3AD516C:6B01AE5C |
| html-safe-nonce | 455bff56126600032ee4412ba146d637fbae6bfbab7b7922483674c9c9b7f8ea |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkZBOjIyREIzNToyRTFBQkIyOjNBRDUxNkM6NkIwMUFFNUMiLCJ2aXNpdG9yX2lkIjoiNDEwNzQ0NDQxNzE1MjAwMzY3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3405d6c9283964198f3dbc053c3baec58deb530c16a0c3aa50c16cff3d21f0b8 |
| hovercard-subject-tag | issue:347056740 |
| 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/26159/issue_layout |
| twitter:image | https://opengraph.githubassets.com/98621b55970ac384a1281a75cce4f0bb2e229ff90c3f0212dbde22488e954ac0/microsoft/TypeScript/issues/26159 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/98621b55970ac384a1281a75cce4f0bb2e229ff90c3f0212dbde22488e954ac0/microsoft/TypeScript/issues/26159 |
| og:image:alt | TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: global Function interface instanceof Type Guard Code declare global { interface Function { now(): string; } } Function.prototype.now = function ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kobiburnley |
| 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