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

[BUG] Type parameter that declared by "extends of" should not be a required type parameter. #39754

Closed
yaquawa opened this issue Jul 26, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@yaquawa
Copy link

yaquawa commented Jul 26, 2020

Here is the code I've got an error.

class Foo<T, K extends keyof T> {
    sayHi(name: K | K[]) {
        console.log(`hi ${name}`);
    }
}

interface Event {
    click(element: string, event: object):void
    touch(element: string, event: object):void
}

const f = new Foo<Event>(); // TS2558: Expected 2 type arguments, but got 1.

Where K is a type that is determined by T automatically, so typescript compiler should not allow users to specify the K type parameter manually.

Did I miss any use cases that a user should specify K manually?

If the K can be an "optional type parameter" that can be specified by user manually , the format should be this I suppose.

class Foo<T, K = keyof T> {
}

By now I'm using this format to avoid the error. But I think this is so pointless..

class Foo<T, K extends keyof T = keyof T> {
}
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 30, 2020
@RyanCavanaugh
Copy link
Member

See #16597 and others

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

3 participants