A
A
Andrey Prozorov2020-11-19 17:37:28
typescript
Andrey Prozorov, 2020-11-19 17:37:28

How to properly type a method decorator?

Good afternoon. Tell me how to type the Compute method

class SomeClass {
 foo: string;
 bar: string

@Compute(['foo', 'bar'])
  fooBar({
    foo,
    bar,
  }): void {}
}


export function Compute<
  T extends { [key: string]: any;  },
  K extends keyof T = keyof T
>( reactiveInputs: K[], reactiveDependency: K[] = [] ): (
  target: T,
  propertyKey: string,
  descriptor: TypedPropertyDescriptor<(newValues: Pick<T, K>) => void>
) => any {
  return (target, name, descriptor) => {}
}


Doesn't work for me 1) Elements of decorat argument array should be pulled from property class. 2) The argument (object) of the fooBar method must have its keys matching the elements of the array from the decorator.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question