Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AndreiPashkin opened this issue Sep 13, 2015 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@AndreiPashkin
Copy link

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[]'.

@danquirk
Copy link
Member

See #4166

@danquirk danquirk added the Duplicate An existing issue was already created label Sep 14, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants