How to correctly type a method decorator?

  • 0
    Good day. 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) => {}
    }


    It doesn't work for me 1) The elements of the decorative argument array must be pulled from the property class. 2) The argument (object) of the fooBar method must have its keys matching the elements of the array from the decorator.
    JavaScript Alice Carney, Jun 11, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!