Given
class A {
props: {
bool?: boolean,
test: string
} = {
test: 'a'
};
setProps(newProps: Partial<this['props']>) {
}
a() {
this.setProps({
bool: false
});
}
}
I get an error
Argument of type
{ bool: false; }is not assignable to parameter of typePartial<this["props"]>.(2345)
As can be viewed here: same code in typescript playground
When the A.props property is defined as {bool?: boolean, test?: string} with test optional it does work, so it looks as if the Partial<> is just completely ignored.
Is there a way to get the Partial to work in conjunction with this.
The above describes the minimal case, for context: My current situation is that I have lots of classes with props that extends from a main class that has a setProps and I would like to type that inherited setProps.
class Parent {
props: any;
setProps(newProps: Partial<this['props']>) {/*...*/}
}
class A extends Parent{
props: {
bool?: boolean,
test: string
} = /* ... */;
a() {
this.setProps({
bool: false
});
}
}