Skip to content

Extending native types works for internal modules, but doesn't for external #4766

@AndreiPashkin

Description

@AndreiPashkin

This one works as expected:

interface Array<T> {
    foo(): number;
}

Array.prototype.foo = function(): number {
    return 42;
}

var arr: string[] = ['a', 'b', 'c'];
var x = arr.foo();

But tsc throws an error for this one:

interface Array<T> {
    foo(): number;
}

Array.prototype['foo'] = function(): number {
    return 42;
}

var arr: string[] = ['a', 'b', 'c'];
var x = arr.foo();
export = x;

The error is: error TS2339: Property 'foo' does not exist on type 'string[]'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions