TypeScript Version: 2.5.3 / nightly (2.6.0-dev.20171010)
Code
interface Foo extends Array<number> {}
class Foo {
constructor() {
super()
}
}
Expected behavior:
'super' can only be referenced in a derived class.
Actual behavior:
no error
InterfaceType.resolvedBaseTypes is used for the check here:
https://github.com/Microsoft/TypeScript/blob/728d2a92ce2f3771ce726f4f6094eba094113ef9/src/compiler/checker.ts#L13030
InterfaceType.resolvedBaseTypes stores the base types for both the class and the interface, as can be seen here:
https://github.com/Microsoft/TypeScript/blob/728d2a92ce2f3771ce726f4f6094eba094113ef9/src/compiler/checker.ts#L27901-L27906
As far as I see, that means we need some means of differentiating between class base types vs. interface base types.
Does that sound right?
Yes, @Kingwl seems to have a PR out right now. Thank you both for digging into this!
Hi , I do have same scenario to call super with out any base class as given below , infact base class constructor should be called through decorator, but typescript is throwing an error "super' can only be referenced in a derived class" please do let me know if its possible.
@Component
export default class HelloWorld {
constructor() {
super();
}
}
Most helpful comment
Yes, @Kingwl seems to have a PR out right now. Thank you both for digging into this!