diff --git a/types/compare-function/compare-function-tests.ts b/types/compare-function/compare-function-tests.ts new file mode 100644 index 0000000000..5381992eea --- /dev/null +++ b/types/compare-function/compare-function-tests.ts @@ -0,0 +1,19 @@ +import compare = require('compare-function'); + +const songs = [{ + artist: 'Joy Division', + track: 'Warsaw' +}, { + artist: 'New Order', + track: 'Blue Monday' +}, { + artist: 'Freebass', + track: 'Plan B' +}]; + +function artist(song: {artist: string}) { + return song.artist; +} + +songs.sort(compare(artist)).map(artist); +songs.sort(compare(-1, artist)).map(artist); diff --git a/types/compare-function/index.d.ts b/types/compare-function/index.d.ts new file mode 100644 index 0000000000..14c46fcd5e --- /dev/null +++ b/types/compare-function/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for compare-function 2.0 +// Project: https://github.com/michaelrhodes/compare-function +// Definitions by: Wolfgang Faust +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function compare(fn: (item: T) => any): (a: T, b: T) => -1 | 0 | 1; +declare function compare(sign: number, fn: (item: T) => any): (a: T, b: T) => -1 | 0 | 1; +export = compare; diff --git a/types/compare-function/tsconfig.json b/types/compare-function/tsconfig.json new file mode 100644 index 0000000000..24264f3c20 --- /dev/null +++ b/types/compare-function/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "compare-function-tests.ts" + ] +} diff --git a/types/compare-function/tslint.json b/types/compare-function/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/compare-function/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }