Typescript: Can't call 'super' when extending from 'any'

Created on 8 Jul 2017  ·  7Comments  ·  Source: microsoft/TypeScript

TypeScript Version: nightly (2.5.0-dev.20170707)

Code

declare const Super: any;
class C extends Super {
    constructor() {
        super();
    }
}

Expected behavior:

No error.

Actual behavior:

src/a.ts(4,3): error TS2346: Call target does not contain any signatures.

Ref: #14935, #14301

Bug Fixed

Most helpful comment

As a workaround, you could use class C extends (Super as { new(): any; }).

All 7 comments

How to solve

As a workaround, you could use class C extends (Super as { new(): any; }).

This form: class A extends ( React.component as { new(): any; } ) is not work. Is there any solution for it?

@sevenryze
You should be able to install @types/react, then import * as React from "react";. Then use React.Component instead of .component and it should be typed (and not need a cast).

@andy-ms yeh, I knew that way, that's works well.
But, for some reason, I want to just use the translate function of typescript(bypass the complex of typing system). So I expect a way to use plain JSX.
I see this issue is marked to bug and added to 2.8 milestone, that's good and I will wait for that time.
Anyway, thanks for your reply!

@sevenryze Actually, with "strict": false, I get no compile error from the following so long as I have react (not even @types/react) installed:

import * as React from "react";
class A extends (React.Component as { new(): any; }) {}

This is because without --noImplicitAny we allow you to import anything in your node_modules even if it lacks typings.

@andy-ms I try that again and confirm that what you told is works well. I think there maybe some config errors in my project and it's my mistake to not make sure of this problems.
Thanks for your answer, good job for TS team!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  ·  3Comments

siddjain picture siddjain  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

Zlatkovsky picture Zlatkovsky  ·  3Comments

MartynasZilinskas picture MartynasZilinskas  ·  3Comments