Giter Club home page Giter Club logo

Comments (5)

ozum avatar ozum commented on August 27, 2024 4

Ah ok,

If you wish you can delete comments of course, I took them from your README.

  • Just create a definition file for each published file:
    • index.d.ts
    • browser/nano-memoize.d.ts
    • dist/nano-memoize.d.ts
  • Copy definitions below into them. Don't forget to add those files to package.json, since they should be included in published npm module.
export default function memoized<T extends Function>(
  func: T,
  options?: {
    /**
     * Only use the provided maxArgs for cache look-up, useful for ignoring final callback arguments
     */
    maxArgs?: number;
    /**
     * Number of milliseconds to cache a result, set to `Infinity` to never create timers or expire
     */
    maxAge?: number;
    /**
     * The serializer/key generator to use for single argument functions (optional, not recommended)
     * must be able to serialize objects and functions, by default a WeakMap is used internally without serializing
     */
    serializer?: (...args: any[]) => any;
    /**
     * the equals function to use for multi-argument functions (optional, try to avoid) e.g. deepEquals for objects
     */
    equals?: (...args: any[]) => boolean;
    /**
     * Forces the use of multi-argument paradigm, auto set if function has a spread argument or uses `arguments` in its body.
     */
    vargs?: boolean;
  }
): T;

Brief Description

Above type definition tells TS compiler, that you are default exporting a function with given parameters.

? indicates optional and not mandatory parameters.

For example equals?: (...args: any[]) => boolean; means, equals optionally expect a function with any inputs which returns a boolean.

<T extends Function>(func: T): T means T is a function. Its signature comes from func parameter and memoized function returns a function which has same signature as func

Hope this helps.

from nano-memoize.

anywhichway avatar anywhichway commented on August 27, 2024

@ozum Thanks for the comment. I am not really sure what to do with it. I have very limited experience with TypeScript.

from nano-memoize.

ercmage avatar ercmage commented on August 27, 2024

Added clear method to typescript declaration, since nano memoize can clear it's cache.

const memo = nanomemoize(someFn)
memo.clear()
declare module 'nano-memoize' {
  interface nanomemoize {
    clear(): void
  }
  export default function memoized<T extends Function>(
    func: T,
    options?: {
      /**
       * Only use the provided maxArgs for cache look-up, useful for ignoring final callback arguments
       */
      maxArgs?: number
      /**
       * Number of milliseconds to cache a result, set to `Infinity` to never create timers or expire
       */
      maxAge?: number
      /**
       * The serializer/key generator to use for single argument functions (optional, not recommended)
       * must be able to serialize objects and functions, by default a WeakMap is used internally without serializing
       */
      serializer?: (...args: any[]) => any
      /**
       * the equals function to use for multi-argument functions (optional, try to avoid) e.g. deepEquals for objects
       */
      equals?: (...args: any[]) => boolean
      /**
       * Forces the use of multi-argument paradigm, auto set if function has a spread argument or uses `arguments` in its body.
       */
      vargs?: boolean
    }
  ): T & nanomemoize
}

from nano-memoize.

MohamedLamineAllal avatar MohamedLamineAllal commented on August 27, 2024

Why this still not merged !??

I would move to fast-memoize just because of the missing typing! As the performance difference is not always mattering! And i don't want to add types manually

(just a feedback! How it can feel)

Otherwise impressive work! Thanks

from nano-memoize.

anywhichway avatar anywhichway commented on August 27, 2024

from nano-memoize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.