Comments (5)
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.
@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.
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.
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.
from nano-memoize.
Related Issues (20)
- Cannot build React app using nano-memoize HOT 3
- that setInterval HOT 41
- Question: How to clear the cache? HOT 3
- Missing serializer causes `TypeError: p is not a function` HOT 2
- Bug on line 40: handling of string argument HOT 5
- Provide es6 modules in package HOT 2
- IE 11 supported? HOT 5
- Curious dependency: growl HOT 1
- Options hash HOT 6
- Bug in vrgs function? HOT 2
- Feature idea: Passing dependencies to the memoizer HOT 2
- Issue with `equals` since 3.0.0 with `fast-deep-equal` HOT 3
- callTimeout option notworking HOT 1
- Benchmarking is flawed and nano-memoize is much slower in realistic scenarios HOT 5
- Performance vs nano-memoize
- clearing cache with max age HOT 3
- missing type definitions HOT 2
- what does "equals" do? HOT 1
- Timeout Leak from `d` function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano-memoize.