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

ParamTypes issue #26

Open
sirian opened this issue Jul 16, 2018 · 4 comments
Open

ParamTypes issue #26

sirian opened this issue Jul 16, 2018 · 4 comments

Comments

@sirian
Copy link

sirian commented Jul 16, 2018

As I mentioned in microsoft/TypeScript#25660 (comment) and in microsoft/TypeScript#21316 (comment)
without inversed check you got wrong result

declare function argTypes<F extends Function>(f: F): ParamTypes<F>

// $ExpectType []
argTypes(() => true); // Expected type to be:  [] got:  {}

// $ExpectType [string, boolean | undefined]
argTypes((x: string, y?: boolean) => true); // Expected type to be:  [string, boolean | undefined] got:  [string]
@pelotom
Copy link
Owner

pelotom commented Jul 16, 2018

Yeah, makes sense. Would you like to make a PR?

@sirian
Copy link
Author

sirian commented Aug 6, 2018

Sorry, have no time. That's my current scratch if smbd will)

type Constructor<T = any, A extends any[] = any[]> = new (...args: A) => T;
type AnyFunction<R = any, A extends any[] = any[]> = (...args: A) => R;
type ArgTypes<F> = 
    F extends AnyFunction<any, infer T> ? T :
    F extends Constructor<any, infer U> ? U :
    F extends Function ? any[] : never;
type ArgCount<F> = ArgTypes<F> extends infer R
    ? (R extends any[] ? R["length"] : never)
    : never;

@pelotom
Copy link
Owner

pelotom commented Aug 6, 2018

Sorry, have no time.

Welcome to the club 🙂

@fbartho
Copy link
Contributor

fbartho commented Oct 18, 2018

We're all here, but we can't stay to chat. No time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants