Skip to content

Commit 7306128

Browse files
committed
Add Typescript definition
1 parent ecb5af2 commit 7306128

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Returns the number of elements in an array.
27+
*
28+
* @param shape - array shape
29+
* @returns number of elements
30+
*
31+
* @example
32+
* var n = numel( [ 3, 3, 3 ] );
33+
* // returns 27
34+
*/
35+
declare function numel( shape: ArrayLike<number> ): number;
36+
37+
38+
// EXPORTS //
39+
40+
export = numel;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 numel = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
numel( [ 3, 2, 1 ] ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided a value other than an array-like object containing numbers...
30+
{
31+
numel( true ); // $ExpectError
32+
numel( false ); // $ExpectError
33+
numel( null ); // $ExpectError
34+
numel( undefined ); // $ExpectError
35+
numel( '5' ); // $ExpectError
36+
numel( [ '1', '2' ] ); // $ExpectError
37+
numel( {} ); // $ExpectError
38+
numel( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
numel(); // $ExpectError
44+
}

lib/node_modules/@stdlib/ndarray/base/numel/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)