Add @types/compare-function. (#35702)

This commit is contained in:
Wolfgang Faust
2019-05-24 16:32:28 -04:00
committed by Ryan Cavanaugh
parent 9cf9f56dd4
commit f506e66ccb
4 changed files with 51 additions and 0 deletions

View File

@@ -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);

8
types/compare-function/index.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
// Type definitions for compare-function 2.0
// Project: https://github.com/michaelrhodes/compare-function
// Definitions by: Wolfgang Faust <https://github.com/wolfgang42>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function compare<T>(fn: (item: T) => any): (a: T, b: T) => -1 | 0 | 1;
declare function compare<T>(sign: number, fn: (item: T) => any): (a: T, b: T) => -1 | 0 | 1;
export = compare;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }