Nessuna descrizione

index.d.ts 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. declare const mimicFn: {
  2. /**
  3. Make a function mimic another one. It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set.
  4. @param to - Mimicking function.
  5. @param from - Function to mimic.
  6. @returns The modified `to` function.
  7. @example
  8. ```
  9. import mimicFn = require('mimic-fn');
  10. function foo() {}
  11. foo.unicorn = '🦄';
  12. function wrapper() {
  13. return foo();
  14. }
  15. console.log(wrapper.name);
  16. //=> 'wrapper'
  17. mimicFn(wrapper, foo);
  18. console.log(wrapper.name);
  19. //=> 'foo'
  20. console.log(wrapper.unicorn);
  21. //=> '🦄'
  22. ```
  23. */
  24. <
  25. ArgumentsType extends unknown[],
  26. ReturnType,
  27. FunctionType extends (...arguments: ArgumentsType) => ReturnType
  28. >(
  29. to: (...arguments: ArgumentsType) => ReturnType,
  30. from: FunctionType
  31. ): FunctionType;
  32. // TODO: Remove this for the next major release, refactor the whole definition to:
  33. // declare function mimicFn<
  34. // ArgumentsType extends unknown[],
  35. // ReturnType,
  36. // FunctionType extends (...arguments: ArgumentsType) => ReturnType
  37. // >(
  38. // to: (...arguments: ArgumentsType) => ReturnType,
  39. // from: FunctionType
  40. // ): FunctionType;
  41. // export = mimicFn;
  42. default: typeof mimicFn;
  43. };
  44. export = mimicFn;