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

Issue with appoint parameter #4709

Closed
OlegDokuka opened this issue Sep 9, 2015 · 7 comments
Closed

Issue with appoint parameter #4709

OlegDokuka opened this issue Sep 9, 2015 · 7 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@OlegDokuka
Copy link

Hi guys, I have gotten issue during compilation and have no idea how to fix it.

The argument type "typeof A" impossible appoint parameter type "{new (): any; new (... args: any []): any;}"

@someannotation
class A {
    constructor(a: string) {

    }
}

here someannotation function

export function someannotation(clazz: Class){

}

here Class definition

 export type Class = {
        new (): any;
        new (...args: any[]): any;
    };

Are there any way to declare new (something here):any that would be available for any kind of constructor include abstract class

@DanielRosenwasser
Copy link
Member

This isn't one of our error messages. Are you using WebStorm?

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Sep 9, 2015
@OlegDokuka
Copy link
Author

nope, it is in russian language.

here is the original message :
TS2345 Аргумент типа "typeof A" нельзя назначить параметру типа "{ new (): any; new (...args: any[]): any; }". Typejector D:\WorkSpace\VisualStudio\Project\Typejector\Typejector\app.ts 2

@DanielRosenwasser
Copy link
Member

Also, our language service seems to be fine with it.

@DanielRosenwasser
Copy link
Member

Just tried it out with 1.6 beta, seeing it. The issue is that your type alias shouldn't have both new (...args: any[]): any; and new (): any; because it requires that A needs both constructor overloads. Try removing new (): any;.

@DanielRosenwasser DanielRosenwasser added Question An issue which isn't directly actionable in code and removed Needs More Info The issue still hasn't been fully clarified labels Sep 9, 2015
@OlegDokuka
Copy link
Author

oh, yep it work fine, but what about abstract class? Ara there any way to use Class for abstract classes

@OlegDokuka
Copy link
Author

Here is an example of code

type Class = {
    new (...args: any[]): any;
};

function someannotation(clazz: Class) {

}

@someannotation
abstract class A {
    constructor(a: string) {

    }
}

@DanielRosenwasser
Copy link
Member

I believe that for now, the only way to do that is to use Function instead of your Class type which what the decorator type declarations use right now. I've brought the issue here up in #4693.

@mhegazy mhegazy closed this as completed Sep 10, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants