Skip to content

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

@ToddThomson

Description

@ToddThomson

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.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy