-
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
Partial<this> not working as expected #16356
Comments
I'm suffering with this as well.
|
Duplicate of #19388.
Seems that what you want here is |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
@mhegazy if I used class Model {
update(values: Partial<Model>): void {}
}
class User {
firstName: string
}
const user = new User()
user.update({ firstName: 'Felix' }) // Property firstName does not exist on type Model |
in this case you need |
Sorry, what do you mean with setting a default in the function body is unsafe? |
async activate(): Promise<void> {
await this.update({ activated: true }); // u do not know what type `activated` will be an a more derived type
} |
Maybe I am misunderstanding you, but any subclass should follow Liskov's substitution principle, so if the superclass declared |
they are substituable for read, but not write.. the sub class are guaranteed to have a type |
Hmm, is there any language feature that would solve this use case? |
|
I refactored the typings of sequelize to use
Partial<this>
to type.update()
, but it is not working as expected.TypeScript Version: 2.3.4
Code
http://www.typescriptlang.org/play/index.html#src=%0D%0Aclass%20User%20%7B%0D%0A%20%20%20%20activated%3A%20boolean%3B%0D%0A%20%20%20%20async%20activate()%3A%20Promise%3Cvoid%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20await%20this.update(%7B%20activated%3A%20true%20%7D)%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20async%20update(keys%3A%20Partial%3Cthis%3E)%3A%20Promise%3Cvoid%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20Do%20SQL%20UPDATE%20query%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A
Expected behavior:
Should compile, as
{ activated: true }
should satisfyPartial<User>
and in turnPartial<this>
Actual behavior:
The text was updated successfully, but these errors were encountered: