Skip to content

Commit 02625bf

Browse files
committed
Add Typescript definition
1 parent 3750f9d commit 02625bf

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Returns the array data type with the smallest size and closest "kind" to which array data types can be safely cast.
23+
*
24+
* @param dtype1 - array data type
25+
* @param dtype2 - array data type
26+
* @returns promotion rule(s) or null
27+
*
28+
* @example
29+
* var dt = promotionRules( 'float32', 'uint32' );
30+
* // returns 'float64'
31+
*
32+
* @example
33+
* var dt = promotionRules( 'float32', 'foo' );
34+
* // returns null
35+
*/
36+
declare function promotionRules( dtype1: string, dtype2: string ): any;
37+
38+
/**
39+
* 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.
40+
*
41+
* @returns promotion rule table
42+
*
43+
* @example
44+
* var table = promotionRules();
45+
* // returns {...}
46+
*/
47+
declare function promotionRules(): any;
48+
49+
50+
// EXPORTS //
51+
52+
export = promotionRules;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import promotionRules = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object, array of strings, or null...
25+
{
26+
promotionRules(); // $ExpectType any
27+
promotionRules( 'float32', 'uint32' ); // $ExpectType any
28+
promotionRules( 'int32', 'generic' ); // $ExpectType any
29+
promotionRules( 'float32', 'foo' ); // $ExpectType any
30+
}
31+
32+
// The function does not compile if provided a first argument that is not a string...
33+
{
34+
promotionRules( 123, 'float64' ); // $ExpectError
35+
promotionRules( true, 'float64' ); // $ExpectError
36+
promotionRules( false, 'float64' ); // $ExpectError
37+
promotionRules( null, 'float64' ); // $ExpectError
38+
promotionRules( {}, 'float64' ); // $ExpectError
39+
promotionRules( ( x: number ): number => x, 'float64' ); // $ExpectError
40+
}
41+
42+
// The function does not compile if provided a second argument that is not a string...
43+
{
44+
promotionRules( 'int32', 123 ); // $ExpectError
45+
promotionRules( 'int32', true ); // $ExpectError
46+
promotionRules( 'int32', false ); // $ExpectError
47+
promotionRules( 'int32', null ); // $ExpectError
48+
promotionRules( 'int32', {} ); // $ExpectError
49+
promotionRules( 'int32', ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The function does not compile if provided more than one argument...
53+
{
54+
promotionRules( 'float32' ); // $ExpectError
55+
promotionRules( 'float32', 'int32', {} ); // $ExpectError
56+
}

lib/node_modules/@stdlib/array/promotion-rules/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)