mobx icon indicating copy to clipboard operation
mobx copied to clipboard

TS complains about @override

Open IanBellomy opened this issue 1 year ago • 3 comments

Moving to finalized decorators and getting a TS complaint about @override.

Using Typescript 5.3.3, Mobx 6.12 with "experimentalDecorators":false.

Screenshot 2024-01-24 at 9 14 29 AM
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
	}
}

IanBellomy avatar Jan 24 '24 14:01 IanBellomy

Hitting this also, @IanBellomy did you find a workaround?

smiley-uriux avatar Sep 27 '24 20:09 smiley-uriux

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.

IanBellomy avatar Sep 27 '24 20:09 IanBellomy

Any update on this one, guys?

I just switched from @override to @computed, and it seems to work in my particular case.

ezze avatar Apr 25 '25 13:04 ezze

Hey, I'm also hitting this issue. @override works fine with legacy decorators (experimentalDecorators), but not with new ones.

marcelgerber avatar Jul 24 '25 16:07 marcelgerber