mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #21439 from mrmlnc/sort_array
[sort-array] Add typings for "sort-array" package
This commit is contained in:
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Type definitions for sort-array 2.0
|
||||
// Project: https://github.com/75lb/sort-array#readme
|
||||
// Definitions by: mrmlnc <https://github.com/mrmlnc>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
type ColumnNames<T> = keyof T | Array<keyof T>;
|
||||
type CustomOrderTypes<T> = Array<T[keyof T]>;
|
||||
type CustomOrder<T> = Record<keyof T, CustomOrderTypes<T>>;
|
||||
|
||||
declare function sortArray<T>(recordset: T[], columnNames: ColumnNames<T>, customOrder?: Partial<CustomOrder<T>>): T[];
|
||||
declare function sortArray(recordset: object[], columnNames: string | string[], customOrder?: Record<string, any[]>): object[];
|
||||
|
||||
export = sortArray;
|
||||
@@ -0,0 +1,37 @@
|
||||
import sort = require('sort-array');
|
||||
|
||||
interface AlphabetItem {
|
||||
letter: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
const alphabet: AlphabetItem[] = [
|
||||
{ letter: 'b', position: 2 },
|
||||
{ letter: 'a', position: 1 },
|
||||
{ letter: 'c', position: 3 }
|
||||
];
|
||||
|
||||
// $ExpectType AlphabetItem[]
|
||||
sort(alphabet, 'letter');
|
||||
sort(alphabet, ['letter']);
|
||||
sort(alphabet, 'letter');
|
||||
|
||||
sort<AlphabetItem>(alphabet, 'letter', { letter: ['c', 'a'] });
|
||||
|
||||
// Allow to use string and number, because we cannot get type of the current property
|
||||
sort<AlphabetItem>(alphabet, 'letter', { letter: ['c', 'a', 1] });
|
||||
|
||||
interface Input {
|
||||
inner: { number: number };
|
||||
}
|
||||
|
||||
const input: Input[] = [
|
||||
{ inner: { number: 5 } },
|
||||
{ inner: { number: 3 } }
|
||||
];
|
||||
|
||||
// Allow to use without types
|
||||
|
||||
// $ExpectType object[]
|
||||
sort(input, 'inner.number');
|
||||
sort(input, 'inner.number', { 'inner.number': [5, 3] });
|
||||
@@ -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",
|
||||
"sort-array-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user