[memoize-one] keep v3 typings

This commit is contained in:
VincentBel
2018-12-14 23:52:26 +08:00
parent 6ca47a427a
commit 77dcb8b3c3
4 changed files with 69 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
// Type definitions for memoize-one 3.1
// Project: https://github.com/alexreardon/memoize-one#readme
// Definitions by: Karol Majewski <https://github.com/karol-majewski>, Frank Li <https://github.com/franklixuefei>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function memoizeOne<T extends (...args: any[]) => any>(resultFn: T, isEqual?: EqualityFn): T;
export type EqualityFn = (a: any, b: any) => boolean;
export default memoizeOne;
+33
View File
@@ -0,0 +1,33 @@
import memoizeOne, { EqualityFn } from 'memoize-one';
declare function add(a: number, b: number): number ;
declare function lousyEqualityFn(a: any, b: any): boolean;
declare function strictEqualityFn<T>(a: T, b: T): boolean;
/**
* Accepts a second argument.
*/
memoizeOne(add); // $ExpectType (a: number, b: number) => number
memoizeOne(add, lousyEqualityFn); // $ExpectType (a: number, b: number) => number
memoizeOne(add, strictEqualityFn); // $ExpectType (a: number, b: number) => number
/**
* The second argument can be, but doesn't have to be strictly typed.
*/
memoizeOne(add, (a, b) => a === b); // $ExpectType (a: number, b: number) => number
memoizeOne(add, (a: string, b: string) => a === b); // $ExpectType (a: number, b: number) => number
/**
* Function passed as the second argument accepts exactly two arguments.
*/
memoizeOne(add, (a: number, b: number, c: number) => a === b || c); // $ExpectError
/**
* Function passed as the second argument returns a boolean.
*/
memoizeOne(add, (a: string, b: string) => 0); // $ExpectError
/**
* The `EqualityFn` type is publicly accessible.
*/
const simpleIsEqual: EqualityFn = (x: number, y: number): boolean => (x === y);
+26
View File
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"paths": {
"memoize-one": [ "memoize-one/v3" ]
},
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"memoize-one-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }