From f506e66ccb495bc6021dbccacffca5c715fc4058 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 24 May 2019 16:32:28 -0400 Subject: [PATCH] Add @types/compare-function. (#35702) --- .../compare-function-tests.ts | 19 +++++++++++++++ types/compare-function/index.d.ts | 8 +++++++ types/compare-function/tsconfig.json | 23 +++++++++++++++++++ types/compare-function/tslint.json | 1 + 4 files changed, 51 insertions(+) create mode 100644 types/compare-function/compare-function-tests.ts create mode 100644 types/compare-function/index.d.ts create mode 100644 types/compare-function/tsconfig.json create mode 100644 types/compare-function/tslint.json 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" }