Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Question: Why does "this" not have a type in function assigned to class prototype  #8024

Copy link
Copy link
@ToddThomson

Description

@ToddThomson
Issue body actions

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.
    }    
}
import { Configuration } from './classes/Configuration';

Configuration.prototype.useLocalStorage = function() {
    this.storage = "NodeFileStorageProvider"
};

Expected behavior:

When walking the AST I use:

let identifier: ts.Identifier = <ts.Identifier>node;
let identifierSymbol: ts.Symbol = this.checker.getSymbolAtLocation( identifier );

to obtain the identifier and its possible associated symbol when the node is SyntaxKind.Identifier.

for 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.

Actual behavior:

I 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.

My expectation was that the reference to storage would have the same symbol ( not undefined ) as the other references to the storage property.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.