class Thing extends ((function () {
return null;
})()) {
doThing() {
}
}
It's a really roundabout way to say extends null
, but the types don't check out, which is awkward. You have to annotate the IIFE with a dummy ctor type like StringConstructor
to satisfy the checker.
This is by design. the only supported form of extending null is extends null
anything else, has to return a value whose type has a construct signature. We have excluded any as a wildcard in this scenario, just because it is more likely a user error here than intended. it would be interesting to see if there are actual use cases where this would be needed.
Here is an interesting case, in TypeScript 2.0 I declare a module swagger-client like:declare module 'swagger-client';
. However, when I try to use it like:
import * as Swagger from 'swagger-client';
class Swagger extends Swagger {
pet: any;
constructor() {
super({
url: config.get('spec.petstore'),
usePromise: true
});
}
}
I get the error Type 'any' is not a constructor function type
.
I got this error when I imported from index file like so:
import {Derived, Base} from '.'
and the derived class was listed in index.ts before the base class:
export {Derived} from './Derived';
export {Base} from './Base';
I switched the order and it worked.
Most helpful comment
Here is an interesting case, in TypeScript 2.0 I declare a module swagger-client like:
declare module 'swagger-client';
. However, when I try to use it like:I get the error
Type 'any' is not a constructor function type
.