-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Faulty declarations file from extending generic base class #17805
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
Comments
@NorlAbrahams referencing class type parameters in the extends clause doesn't make sense - the extends clause is executed once (to find the base class), but the type parameters are reinstantiated on every constructor call. If the goal is to pass on the generic into the extending class, that's still possible (ie, extending a generic base class), it's just not possible to use the type parameters in the actual extends clause expression, since they'll never be instantiated with real types there. |
@weswigham I had already chickened out and deleted my comment. But thanks for the explanation! |
Hello, I don't understand why did you do that ? This was only single way to create generic mixins. Now I can't migrate to 2.8 because there is no alternative for this feature This code works perfect in 2.3.2 // The goal to add generic method via mixin
function ValidatorMixin<T extends { new (...args: any[]): {} }, V>(
BaseClass: T,
validate: (arg: V) => boolean
) {
abstract class Validator extends BaseClass {
value: V;
validate(value: V) {
return validate(value);
}
}
return Validator;
}
class BaseInput {}
class StringInput<T = string> extends ValidatorMixin(
BaseInput,
(value: T) => typeof value === 'string'
) {
}
// ValidatorValueType will be string | null | undefined
type ValidatorValueType = StringInput<string | null | undefined>['value']; And now it has thrown an error. Yes there is a problem with extending static properties, but maybe you could make this check opinionated via additional flag like for strict generic |
TypeScript Version: 2.4.1
Code
Expected behavior:
The generated declaration file should contain the following
Actual behavior:
When the generated declarations file is referenced by other code, the compilation fails with
The text was updated successfully, but these errors were encountered: