Skip to content
New issue

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

Error TS2346 when importing React components written in JavaScript #15375

Closed
mohsen1 opened this issue Apr 25, 2017 · 6 comments
Closed

Error TS2346 when importing React components written in JavaScript #15375

mohsen1 opened this issue Apr 25, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Apr 25, 2017

TypeScript Version: 2.3.0

Code
See repo here: https://github.com/mohsen1/ts23-super-issue

import React from 'react';

export default class Component extends React.Component {
    constructor(...args) {
        super(...args)
    }
}

Expected behavior:

No error

Actual behavior:

Error: src/component.js(5,9): error TS2346: Supplied parameters do not match any signature of call target.
@mhegazy
Copy link
Contributor

mhegazy commented Apr 25, 2017

Covered by #5296

@mohsen1
Copy link
Contributor Author

mohsen1 commented Apr 30, 2017

This is a very common pattern in React. For now we can @ts-ignore that line.

import React from 'react';

export default class Component extends React.Component {
    constructor(...args) {
        // @ts-ignore
        super(...args)
    }
}

@silicakes
Copy link

It also seems that TypeScript ignores the good 'ol es5 spread pattern:
super.apply(this, ...args);

A more complete demo:

function bar(a: any, b: any, c: any): void { 
    console.log(a, b, c);
}

function foo(a: number, b: number, c: number): void {
    bar.apply(null, arguments);
}

@Almenon
Copy link

Almenon commented Jun 9, 2018

Has this not been fixed or am I doing someting wrong? Just ran into this issue with typescript 2.9.1

    public handleSpawnError(pythonCommand:string, pythonPath:string, err:string){
        this.pythonPreview.handleSpawnError(...arguments)
         // gives me error: Expected three arguments, but got 0 or more
    }

pythonPreview:

    public handleSpawnError(pythonCommand:string, pythonPath:string, err:string){
        // ... code is irrelevant
    }

@shirshak55
Copy link

(super as any)(...args)

@bluEEil
Copy link

bluEEil commented Nov 29, 2020

I couldn't find online any good solution to writing stuffs like:

authenticateUser = (...args: any[]) => this.authManager.authenticateUser(...args);

Is there any update on a way to do this without having to do something ugly like:

authenticateUser = (...args: any[]) => (this.authManager.authenticateUser as any)(...args);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants