Closed
Description
Bug Report
After extracting a method from a class prototype (which becomes a plain function), the polymorphic this
still behaves like the function is attached to the class prototype.
🔎 Search Terms
polymorphic this
🕗 Version & Regression Information
I saw this happening in the latest current version (4.4.2) and I don't know since when the bug exists.
⏯ Playground Link
Playground link with relevant code
💻 Code
class Foo {
axisControl: string = "string";
directionControl: string = "string";
filteredAxis: string[] = ["string"];
filteredDirection: string[] = ["string"];
test(filteredName: `filtered${string}` & keyof this) {
return this[filteredName];
}
}
const foo = new Foo;
const result = foo.test("filteredAxis"); // Type resolves here: string[]
const test = Foo.prototype.test;
const wrong = test("filteredAxis"); // It also resolves here to string[]
const bound = test.bind(undefined);
const wrong2 = bound("filteredAxis"); // It also resolves here to string[]
const wrong3 = Foo.prototype.test.apply(undefined, ["filteredAxis"]); // It also resolves here to string[]
const wrong4 = Foo.prototype.test.call(undefined, "filteredAxis"); // It also resolves here to string[]
🙁 Actual behavior
The wrong
, wrong2
, wrong3
, wrong4
variables types resolves to string[]
🙂 Expected behavior
Compilation errors to prevent the TypeError: Cannot read properties of undefined
runtime errors