After update 0.15.0 the "field" decorator started to give an error in typescrip.
Unable to resolve signature of property decorator when called as an expression.
This expression is not callable.
Not all constituents of type 'Object | RawDecorator' are callable.
Type 'Object' has no call signatures.
I also have the issue, it is caused by the fact that the Descriptor of the makeDecorator is mapped to Object, I managed to resolve that by changing the Descriptor definition to:
export type Descriptor = any
in /utils/common/makeDecorator/index.d.ts
Is there any way to monkey patch this just with typescript?
nvm ended up using patch-package to modify the types, in /utils/common/makeDecorator/index.d.ts:
declare module '@nozbe/watermelondb/utils/common/makeDecorator' {
import { ReplaceReturn } from '@nozbe/watermelondb/utils/common';
export type Descriptor = any;
export type RawDecorator = (
target: Object,
key: string,
descriptor: Descriptor,
) => Descriptor;
export type RawDecoratorFactory<T extends any[]> = (
...any: T
) => RawDecorator;
export type Decorator<
Args extends any[],
Factory extends RawDecoratorFactory<Args>
// TODO: fix
> = any;
export default function makeDecorator<
Args extends any[],
T extends RawDecoratorFactory<Args>
>(): Decorator<Args, T>;
}
@ospfranco I did the same thing but there is also an issues with @readonly since it wants @readonly() an in the case where you have @readonly @field('aField') aField: string; not sure if it is correct to replace it with @readonly(). One solution is to remove it for know which from what @radex said in the documentation would have probably a minimal performance impact since read-only fields might get optimized.
I am also experiencing this error. Looks to be related to #529
nvm ended up using patch-package to modify the types, in
/utils/common/makeDecorator/index.d.ts:
@ospfranco Wow. This is the first I've heard of patch-package. Perfect! Thanks for sharing.
Can we get a fix that's not that hacky ? @radex Thanks mate
@ScreamZ Please contribute!
@ScreamZ Please contribute!
I'll sir! Thanks for quick answer :)
@radex How are the types generated? If you give me a starting point I'll definitely help fix the typescript type on this.
I haven't used Flow before so I'm not sure what the build tools look like. I looked in the package.json and scripts directory and didn't see anything obvious.
I see that there are .d.ts files in the project, are those manually coded? If so I'll raise a PR with it like now
Hi @cranesandcaff, I suggest something like https://github.com/Nozbe/WatermelonDB/pull/613
I also have the issue, it is caused by the fact that the
Descriptorof themakeDecoratoris mapped to Object, I managed to resolve that by changing theDescriptordefinition to:export type Descriptor = anyin
/utils/common/makeDecorator/index.d.ts
was this fix merged?
Most helpful comment
nvm ended up using patch-package to modify the types, in
/utils/common/makeDecorator/index.d.ts: