-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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/generics]: Class Generics doesn't flow properly to subclass generics #25296
Comments
The first issue seems like the right behavior, your The second case, i only see one error on |
type Props<T extends string = string> = {
items: T[]
name: string
// error
- onSelect: (item: T, event?: SyntheticEvent<HTMLElement>) => void
// no error
+ onSelect(item: T, event?: SyntheticEvent<HTMLElement>): void
}
Any more explanations are more than welcome 👌:) |
default type is of no consequence here. |
AHA ! right ! so with that solved what about the strange behaviour in 1): type Props<T extends string = string> = {
items: T[]
name: string
// error
- onSelect: (item: T, event?: SyntheticEvent<HTMLElement>) => void
// no error
+ onSelect(item: T, event?: SyntheticEvent<HTMLElement>): void
} thanks ! |
|
Oh wow ! Didn't know that this applies also for ambient definitions ! Thanks so much for making things clear , much appreciated. Closing now 👌✌️ |
…er contravariant checks - microsoft/TypeScript#25296 (comment)
TypeScript Version: 2.9.2 +
{strict:true}
Search Terms:
jsx generics, class generics
I wanna create React generic component. but the generic annotations flow doesn't work properly/is acting strange
Code
There are various issues with generics flow:
1. When I define Props member, which is type of function via property, following throws error:
but if i change it to "method" definition, error is gone
2. Generics default values doesn't flow properly:
throws
T = {}
is not propagated correctly to Props and because of that we have those errors.What partially helps is to constraining generic to
string
in this case, but event with that it won't flow to our Props['onSelect']throws:
finally what fixes the issue is to cast value propagated to
onSelect
to ourT
Expected behavior:
class generics should properly flow to subclasses generics
The text was updated successfully, but these errors were encountered: