Skip to content

Commit 3e1d7c2

Browse files
committed
Add Typescript definitions
1 parent d544674 commit 3e1d7c2

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 a list of array data types to which a provided array data type can be safely cast.
23+
*
24+
* ## Notes
25+
*
26+
* - If not provided an array data type, the function returns a casting table.
27+
* - If provided an unrecognized array data type, the function returns `null`.
28+
*
29+
* @param dtype - array data type
30+
* @returns list of array data types or null
31+
*
32+
* @example
33+
* var list = safeCasts( 'float32' );
34+
* // returns [...]
35+
*/
36+
declare function safeCasts( dtype?: string ): Object | Array<string> | null;
37+
38+
39+
// EXPORTS //
40+
41+
export = safeCasts;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 safeCasts = require( './index' );
20+
21+
// TESTS //
22+
23+
// The function returns a string array, object, or null..
24+
{
25+
safeCasts(); // $ExpectType Object | string[] | null
26+
safeCasts( 'float32' ); // $ExpectType Object | string[] | null
27+
}
28+
29+
// The compiler throws an error if the function is provided a first argument which is not a string...
30+
{
31+
safeCasts( 123 ); // $ExpectError
32+
safeCasts( true ); // $ExpectError
33+
safeCasts( false ); // $ExpectError
34+
safeCasts( {} ); // $ExpectError
35+
safeCasts( [] ); // $ExpectError
36+
safeCasts( null ); // $ExpectError
37+
}
38+
39+
// The compiler throws an error if the function is provided an unsupported number of arguments...
40+
{
41+
safeCasts( 'float32', 3 ); // $ExpectError
42+
}

lib/node_modules/@stdlib/array/safe-casts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24-
"scripts": {},
24+
"types": "./docs/types",
25+
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {
2728
"type": "git",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 a list of array data types to which a provided array data type can be safely cast or cast within the same "kind".
23+
*
24+
* ## Notes
25+
*
26+
* - If not provided an array data type, the function returns a casting table.
27+
* - If provided an unrecognized array data type, the function returns `null`.
28+
*
29+
* @param dtype - array data type
30+
* @returns list of array data types or null
31+
*
32+
* @example
33+
* var list = sameKindCasts( 'float32' );
34+
* // returns [...]
35+
*/
36+
declare function sameKindCasts( dtype?: string ): Object | Array<string> | null;
37+
38+
39+
// EXPORTS //
40+
41+
export = sameKindCasts;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 sameKindCasts = require( './index' );
20+
21+
// TESTS //
22+
23+
// The function returns a string array, object, or null..
24+
{
25+
sameKindCasts(); // $ExpectType Object | string[] | null
26+
sameKindCasts( 'float32' ); // $ExpectType Object | string[] | null
27+
}
28+
29+
// The compiler throws an error if the function is provided a first argument which is not a string...
30+
{
31+
sameKindCasts( 123 ); // $ExpectError
32+
sameKindCasts( true ); // $ExpectError
33+
sameKindCasts( false ); // $ExpectError
34+
sameKindCasts( {} ); // $ExpectError
35+
sameKindCasts( [] ); // $ExpectError
36+
sameKindCasts( null ); // $ExpectError
37+
}
38+
39+
// The compiler throws an error if the function is provided an unsupported number of arguments...
40+
{
41+
sameKindCasts( 'float32', 3 ); // $ExpectError
42+
}

lib/node_modules/@stdlib/array/same-kind-casts/package.json

Lines changed: 1 addition & 0 deletions
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)