-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Default method generic doesn't apply from class generic #20505
Comments
A default for a type parameter in a function only applies if a type can't be inferred. (Note that it's not using |
I am building REST api layer.. but data could be different and response could be different for the same method. So what I want is to define default type of request and type of response. But sometimes there is a need of overwriting it... I can create custom method to handle it but thought I can do it just with generics as everything else is the same |
So, you want a parameter that's not |
I see.. basically it is not possible right now, here is my definitions to illustrate what I mean:
So I define instance like
then I can do type-checking like:
|
There's still type-checking even if you provide explicit type arguments. So |
If you want to do both, verify an upper bound, and set a default, use class TestClass<T_MODEL = any> {
create<T_DATA extends T_MODEL = T_MODEL>(data: T_DATA) {
// todo
}
} this will give an error on both: testString.create(1) ;
testString.create<number>(1); |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Code
Expected behavior:
By method default generic should use generic from the class
Actual behavior:
while it ignores default value: create<T_DATA = T_MODEL> and applies any
The text was updated successfully, but these errors were encountered: