You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow type assertion for "super" keyword in method. #41034
Currently there is no way to provide a type assertion for "super" keyword, because the "super" keyword cannot be wrapped by parentheses, so either (<T>super).x or (super as T).x will result in an error: "'super' must be followed by an argument list or member access.ts(1034)".
The parentheses wrapping "super" which only for type assertion use should be allowed.
Use Cases
class A {
// a decorator will add a instance method "foo" here.
}
class B extends A {
bar() {
(<A & {foo: () => void}>super).foo(); // doesn't work.
}
}
class C extends A {
bar() {
(<A & {foo: () => void}>A.prototype).foo(); // this works.
}
}
Checklist
My suggestion meets these guidelines:
[●] This wouldn't be a breaking change in existing TypeScript/JavaScript code
[●] This wouldn't change the runtime behavior of existing JavaScript code
[●] This could be implemented without emitting different JS based on the types of the expressions
[●] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Activity
whzx5byb commentedon Oct 10, 2020
TS do removes the wrapping parenthesis.
(this as any).x();will compile tothis.x();link