Skip to content

Property 'x' does not exist on type 'any[]'. when exporting class. #8278

@sorgloomer

Description

@sorgloomer

Hi guys!

We ran into a strange behaviour on StackOverflow regarding the typescript compiler. We were trying to extend the Array interface, and it worked well until we exported something. I don't know what is the expected behavior when extending builtin types interfaces, sorry if I am wrong here, but as I see a seemingly unrelated export should not affect the validity of that.

The report originates from: http://stackoverflow.com/questions/36805280/how-to-add-tolist-method-into-typescript-arrayt-class/36810621?noredirect=1#comment61231653_36810621

TypeScript Version:

Whatever version was published on the Playground (https://www.typescriptlang.org/play/index.html) on 2016.04.25. (I couldn't find it out)

Code

interface Array<T> {
    ToList():List<T>;
};

class List<T> {
    constructor(items: T[]) {}
};

Array.prototype.ToList = function() {
    return new List(this);
};

export default "anything";

Expected behavior:

Should compile. The strange thing is that when I remove the export the error vanishes.

Actual behavior:

Compilation error is shown on Array.prototype.ToList =: Property 'ToList' does not exist on type 'any[]'.

Thanks

Metadata

Metadata

Assignees

Labels

DocsThe issue relates to how you learn TypeScriptQuestionAn issue which isn't directly actionable in code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions