Title: Question: Why does "this" not have a type in function assigned to class prototype · Issue #8024 · microsoft/TypeScript · GitHub
Open Graph Title: Question: Why does "this" not have a type in function assigned to class prototype · Issue #8024 · microsoft/TypeScript
X Title: Question: Why does "this" not have a type in function assigned to class prototype · Issue #8024 · microsoft/TypeScript
Description: TypeScript Version: 1.8.9 Code export class Configuration { private storage: string; constructor() { this.storage = "InMemoryStorageProvider()"; } public useLocalStorage(): void { // This method will be injected via the prototype. } } im...
Open Graph Description: TypeScript Version: 1.8.9 Code export class Configuration { private storage: string; constructor() { this.storage = "InMemoryStorageProvider()"; } public useLocalStorage(): void { // This method wi...
X Description: TypeScript Version: 1.8.9 Code export class Configuration { private storage: string; constructor() { this.storage = "InMemoryStorageProvider()"; } public useLocalStorage(): void { // This...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/8024
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Question: Why does \"this\" not have a type in function assigned to class prototype ","articleBody":"**TypeScript Version:** \n\n1.8.9\n\n**Code**\n\n``` configuration.ts\nexport class Configuration {\n private storage: string;\n\n constructor() {\n this.storage = \"InMemoryStorageProvider()\";\n }\n\n public useLocalStorage(): void {\n // This method will be injected via the prototype.\n } \n}\n```\n\n``` prototypetest.ts\nimport { Configuration } from './classes/Configuration';\n\nConfiguration.prototype.useLocalStorage = function() {\n this.storage = \"NodeFileStorageProvider\"\n};\n```\n\n**Expected behavior:**\n\nWhen walking the AST I use:\n\n```\nlet identifier: ts.Identifier = \u003cts.Identifier\u003enode;\nlet identifierSymbol: ts.Symbol = this.checker.getSymbolAtLocation( identifier );\n```\n\nto obtain the identifier and its possible associated symbol when the node is SyntaxKind.Identifier.\n\nfor the first 2 references to the private property `storage`, I obtain the identifier and the symbol (which correctly have the same `Id`). With the prototype function assigned to useLocalStorage the reference to `storage` the call to `this.checker.getSymbolAtLocation( identifier )` does not return a symbol.\n\n**Actual behavior:** \n\nI am using the AST to identify identifiers which may be minified/shortened. The 1st and 2nd reference to `storage` gets shortened as it is a private property.\n\nMy expectation was that the reference to `storage` would have the same symbol ( not undefined ) as the other references to the `storage` property. \n","author":{"url":"https://github.com/ToddThomson","@type":"Person","name":"ToddThomson"},"datePublished":"2016-04-12T14:57:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/8024/TypeScript/issues/8024"}
| 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:76a7d4be-98a0-76f6-ca0c-413fe5bcd7f7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8AEC:169AD6:1C9F9:28781:6A62F5AC |
| html-safe-nonce | 8b1e606e059ea1e02be30f2d5bf08e3364c7bda6daf5bafd0214b7981962e909 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUVDOjE2OUFENjoxQzlGOToyODc4MTo2QTYyRjVBQyIsInZpc2l0b3JfaWQiOiI1MTA4NTY1OTQxOTYzMzg4MzMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 869a6a52badbeca960d6d757e2817e48954c4d5d3246348d52cb0350264f6f2c |
| hovercard-subject-tag | issue:147778380 |
| 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/8024/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ee5dcd256ca22bbd8c98fb1b2ff680f99758f4f506d75280b184c8e6029395d4/microsoft/TypeScript/issues/8024 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ee5dcd256ca22bbd8c98fb1b2ff680f99758f4f506d75280b184c8e6029395d4/microsoft/TypeScript/issues/8024 |
| og:image:alt | TypeScript Version: 1.8.9 Code export class Configuration { private storage: string; constructor() { this.storage = "InMemoryStorageProvider()"; } public useLocalStorage(): void { // This method wi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ToddThomson |
| hostname | github.com |
| expected-hostname | github.com |
| None | b415018e190e73858133ddcaa36acce7b3f3572fe54dda84bd3b21a6ec714c30 |
| 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 | 22f98521e99f504294ab0812b66104d50eb75a70 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width