We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: getter/setter, subclassing
Code
const x: any = [] class A { a() { x.push(this); return this; } get s() { x.push(this); return this; } set s(n: any) { x.push(this); } } class B extends A { a() { x.push(this); return super.a(); } get s() { x.push(this); // @ts-ignore return super.s; } set s(n: any) { x.push(this); // @ts-ignore super.s = n; } } const b = new B(); b.a(); b.s; b.s = 1; console.log([x[0] === x[1], x[2] === x[3], x[4] === x[5]]);
ts compiler:Only public and protected methods of the base class are accessible via the 'super' keyword.ts(2340) and // @ts-ignore.
Only public and protected methods of the base class are accessible via the 'super' keyword.ts(2340)
// @ts-ignore
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var x = []; var A = /** @class */ (function () { function A() { } A.prototype.a = function () { x.push(this); return this; }; Object.defineProperty(A.prototype, "s", { get: function () { x.push(this); return this; }, set: function (n) { x.push(this); }, enumerable: true, configurable: true }); return A; }()); var B = /** @class */ (function (_super) { __extends(B, _super); function B() { return _super !== null && _super.apply(this, arguments) || this; } B.prototype.a = function () { x.push(this); return _super.prototype.a.call(this); }; Object.defineProperty(B.prototype, "s", { get: function () { x.push(this); // @ts-ignore return _super.prototype.s; }, set: function (n) { x.push(this); // @ts-ignore _super.prototype.s = n; }, enumerable: true, configurable: true }); return B; }(A)); var b = new B(); b.a(); b.s; b.s = 1; console.log([x[0] === x[1], x[2] === x[3], x[4] === x[5]]);
{ "compilerOptions": { "target": "es5" } }
Expected behavior: [ true, true, true ]
Actual behavior: [ true, false, false ]
Playground Link:
Related Issues: Allow to call getter/setter logic When subclassing
The text was updated successfully, but these errors were encountered:
Can't reproduce on 3.7.5 playground: Playground Link
Sorry, something went wrong.
Duplicate #338; using getters/setters via super is not supported in target: ES5. The code runs as expected in ES6+ target
super
The errors you're ignoring are the errors which are telling you that this won't work...
Got it. so sad.
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
getter/setter, subclassing
Code
ts compiler:
Only public and protected methods of the base class are accessible via the 'super' keyword.ts(2340)
and// @ts-ignore
.Output
Compiler Options
Expected behavior:
[ true, true, true ]
Actual behavior:
[ true, false, false ]
Playground Link:
Related Issues:
Allow to call getter/setter logic When subclassing
The text was updated successfully, but these errors were encountered: