Skip to content

Commit 3a608ea

Browse files
committed
Add overloads
1 parent 861bc6e commit 3a608ea

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

lib/node_modules/@stdlib/array/promotion-rules/docs/types/index.d.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,31 @@
1818

1919
// TypeScript Version: 2.0
2020

21+
/// <reference types="@stdlib/types"/>
22+
23+
import { DataType } from '@stdlib/types/array';
24+
2125
/**
2226
* Interface describing a promotion table.
2327
*/
2428
interface Table {
25-
// Table properties:
26-
[key: string]: string | number;
29+
/**
30+
* Data type promotion rules.
31+
*/
32+
[key: string]: DataType | number;
2733
}
2834

35+
/**
36+
* Promotion rule.
37+
*/
38+
type PromotionRule = DataType | number;
39+
2940
/**
3041
* Returns the array data type with the smallest size and closest "kind" to which array data types can be safely cast.
3142
*
3243
* @param dtype1 - array data type
3344
* @param dtype2 - array data type
34-
* @returns promotion rule(s) or null
45+
* @returns promotion rule
3546
*
3647
* @example
3748
* var dt = promotionRules( 'float32', 'uint32' );
@@ -41,11 +52,34 @@ interface Table {
4152
* var dt = promotionRules( 'float32', 'foo' );
4253
* // returns null
4354
*/
44-
declare function promotionRules( dtype1: string, dtype2: string ): number | string | null; // tslint-disable-line max-line-length
55+
declare function promotionRules( dtype1: DataType, dtype2: DataType ): PromotionRule; // tslint:disable-line:max-line-length
56+
57+
/**
58+
* Returns the array data type with the smallest size and closest "kind" to which array data types can be safely cast.
59+
*
60+
* @param dtype1 - array data type
61+
* @param dtype2 - array data type
62+
* @returns promotion rule
63+
*
64+
* @example
65+
* var dt = promotionRules( 'float32', 'foo' );
66+
* // returns null
67+
*
68+
* @example
69+
* var dt = promotionRules( 'bar', 'float32' );
70+
* // returns null
71+
*
72+
* @example
73+
* var dt = promotionRules( 'bar', 'foo' );
74+
* // returns null
75+
*/
76+
declare function promotionRules( dtype1: string, dtype2: string ): null;
4577

4678
/**
4779
* Returns a type promotion table displaying array data types with the smallest size and closest "kind" to which array data types can be safely cast.
4880
*
81+
* @param dtype1 - array data type
82+
* @param dtype2 - array data type
4983
* @returns promotion rule table
5084
*
5185
* @example

lib/node_modules/@stdlib/array/promotion-rules/docs/types/test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ import promotionRules = require( './index' );
2121

2222
// TESTS //
2323

24-
// The function returns an object, array of strings, or null...
24+
// The function returns an object when not provided any arguments...
2525
{
2626
promotionRules(); // $ExpectType Table
27-
promotionRules( 'float32', 'uint32' ); // $ExpectType string | number | null
28-
promotionRules( 'int32', 'generic' ); // $ExpectType string | number | null
29-
promotionRules( 'float32', 'foo' ); // $ExpectType string | number | null
27+
}
28+
29+
// The function returns a promoted data type promotion rule when provided recognized data types...
30+
{
31+
promotionRules( 'float32', 'uint32' ); // $ExpectType PromotionRule
32+
promotionRules( 'int32', 'generic' ); // $ExpectType PromotionRule
33+
}
34+
35+
// The function returns null when provided unrecognized data types...
36+
{
37+
promotionRules( 'float32', 'foo' ); // $ExpectType null
38+
promotionRules( 'bar', 'foo' ); // $ExpectType null
39+
promotionRules( 'bar', 'float32' ); // $ExpectType null
3040
}
3141

3242
// The function does not compile if provided a first argument that is not a string...

0 commit comments

Comments
 (0)