Title: Extending the Function interface in the presence of an import statement · Issue #5944 · microsoft/TypeScript · GitHub
Open Graph Title: Extending the Function interface in the presence of an import statement · Issue #5944 · microsoft/TypeScript
X Title: Extending the Function interface in the presence of an import statement · Issue #5944 · microsoft/TypeScript
Description: I would like to extend Function and this compiles fine interface Function { hello(): any } Function.prototype.hello = function() { console.log('hello world') } function noop() {} noop.hello() //==> 'hello world' in the console However, a...
Open Graph Description: I would like to extend Function and this compiles fine interface Function { hello(): any } Function.prototype.hello = function() { console.log('hello world') } function noop() {} noop.hello() //==>...
X Description: I would like to extend Function and this compiles fine interface Function { hello(): any } Function.prototype.hello = function() { console.log('hello world') } function noop() {} noop.hello...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5944
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Extending the Function interface in the presence of an import statement","articleBody":"I would like to extend `Function` and this compiles fine\n\n```\ninterface Function {\n hello(): any\n}\nFunction.prototype.hello = function() {\n console.log('hello world')\n}\n\nfunction noop() {}\n\nnoop.hello() //==> 'hello world' in the console\n```\n\nHowever, as soon as I try to add an import statement, say\n\n```\nimport { sayHello } from './Anything'\n```\n\nwhere `Anything` only contains\n\n```\nexport function sayHello() { console.log('hello')}\n```\n\nThe compilation fails on `Function.protoype.hello` with the message `error TS2339: Property 'hello' does not exist on type 'Function'`\n\nWhy ?\n\n[View in Playground](http://www.typescriptlang.org/Playground#src=%0A%20%20%20%20interface%20Function%20%7B%0A%20%20%20%20%09hello%28%29%3A%20any%0A%20%20%20%20%7D%0A%20%20%20%20Function.prototype.hello%20%3D%20function%28%29%20%7B%0A%20%20%20%20%09console.log%28'hello%20world'%29%0A%20%20%20%20%7D%0A%09%0A%09function%20noop%28%29%20%7B%7D%0A%09%0A%09noop.hello%28%29%0A%09%0A%09%2F%2Fimport%20%7B%20hello%20%7D%20from%20'whatever'%20%20%0A%09%2F*%0A%09%20*%20Adding%20the%20import%20statement%20%28also%29%20triggers%20the%20Error%3A%20%0A%09%20*%20Property%20'hello'%20does%20not%20exists%20on%20type%20%60Function%60%0A%09%20*%20Why%20%3F%0A%09%20*%2F)\n\nNote1: the compilation fails with tsc options set to either `--target es5 --module commonjs` or `--target es6`\nNote2: my final goal is to export utilities in a library to be able to write code like `myfunc.liftM(myMonad1, MyMonad2)` or `myfunc1.compose(myfunc2)`, etc...\n","author":{"url":"https://github.com/bgrieder","@type":"Person","name":"bgrieder"},"datePublished":"2015-12-05T05:35:21Z","url":"https://github.com/microsoft/TypeScript/issues/5944"}
| 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:f16c578e-7314-1fa2-3bb1-248e4a810f97 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBBC:ADA9D:120DAB8:174DD76:6B010EF8 |
| html-safe-nonce | 01c9685b3ca5f37edcf8eac10c7a3ddf78ce5de0150afd24de242dcd69f650e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkJDOkFEQTlEOjEyMERBQjg6MTc0REQ3Njo2QjAxMEVGOCIsInZpc2l0b3JfaWQiOiI0NTYyOTI4ODQ3MTAzNzkwODQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7f5ece649c508a355b097f1ff6b91c7a60d32d5acc864b6519627c0860276124 |
| hovercard-subject-tag | issue:120531275 |
| 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/5944/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e2cffe6e2c81cce6fb1bf379ee1756fe23a9019c3d7ee233101cc6a492e7545a/microsoft/TypeScript/issues/5944 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e2cffe6e2c81cce6fb1bf379ee1756fe23a9019c3d7ee233101cc6a492e7545a/microsoft/TypeScript/issues/5944 |
| og:image:alt | I would like to extend Function and this compiles fine interface Function { hello(): any } Function.prototype.hello = function() { console.log('hello world') } function noop() {} noop.hello() //==>... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bgrieder |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width