mobx
mobx copied to clipboard
TS complains about @override
Moving to finalized decorators and getting a TS complaint about @override.
Using Typescript 5.3.3, Mobx 6.12 with "experimentalDecorators":false.
Unable to resolve signature of method decorator when called as an expression.
No overload matches this call.
Overload 1 of 2, '(target: Object, propertyKey: string | symbol): void', gave the following error.
Argument of type 'ClassGetterDecoratorContext<Sub, number> & { name: "val"; private: false; static: false; }' is not assignable to parameter of type 'string | symbol'.
Overload 2 of 2, '(value: any, context: ClassMethodDecoratorContext<any, any>): any', gave the following error.
Argument of type 'ClassGetterDecoratorContext<Sub, number> & { name: "val"; private: false; static: false; }' is not assignable to parameter of type 'ClassMethodDecoratorContext<any, any>'.
Types of property 'kind' are incompatible.
Type '"getter"' is not assignable to type '"method"'.ts(1241)
override's type seems to include ClassMethodDecorator though not ClassGetterDecorator but I haven't found anything in docs about no longer using @override for subclass getters, so I'm not sure if this typing is intentional and if so what preferred approach is for handling subclass overrides sans makeObservable.
Copyable Code:
import { computed, override } from "mobx"
class Main{
@computed
get val(){
return 1
}
}
class Sub extends Main{
@override
override get val(){
return 1
}
}
Hitting this also, @IanBellomy did you find a workaround?
Don't believe so — IIRC I tabled the project's switch to finalized decorators until this and other decorator related issues in the pipeline got ironed out. Haven't circled back yet.
Any update on this one, guys?
I just switched from @override to @computed, and it seems to work in my particular case.
Hey, I'm also hitting this issue.
@override works fine with legacy decorators (experimentalDecorators), but not with new ones.