-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Extending a class using interface and ES6 Proxy #28776
Copy link
Copy link
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
I checked the FAQ and didn't see anything related to this problem and didn't find anything I thought looked related. I'll admit that the code snippet below doesn't come from a place of complete comprehension of Typescript and inheritance, so it's possible that a language feature exists I'm not aware of, but as it stands I can't get my code to compile.
Search Terms:
typescript es6 proxy interfacetypescript interface missing property
Code
interface IArrayProxy<T> extends Array<T> {}
// @ts-ignore I'm okay with needing this because the case is somewhat exceptional
class ArrayProxy<T> implements IArrayProxy<T> {
constructor(protected array: T[]) {
return new Proxy(this, this);
}
public get(target: any, prop: string) {
return this.hasOwnProperty(prop) ? this[prop] : this.array[prop];
}
// More functions below
}
const arrayProxy = new ArrayProxy([]);
console.log(arrayProxy['length']); // <--- Compiles and gives desired output
console.log(arrayProxy.length); // <-- Gives desired output but doesn't compileExpected behavior: The entire block compiles and runs correctly
Actual behavior: The block doesn't compile because of the final line
Playground Link: link to playground
Related Issues: N/A
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code