Skip to content

Commit 61d3a19

Browse files
committed
Add Typescript annotations
1 parent 2ae1ed6 commit 61d3a19

File tree

15 files changed

+586
-0
lines changed

15 files changed

+586
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 { PropertyName } from '@stdlib/types/object';
24+
25+
/**
26+
* Defines a non-enumerable property.
27+
*
28+
* ## Notes
29+
*
30+
* - Non-enumerable properties are writable and configurable.
31+
*
32+
* @param obj - object on which to define the property
33+
* @param prop - property name
34+
* @param value - value to set
35+
*
36+
* @example
37+
* var objectKeys = require( '@stdlib/utils/keys' );
38+
*
39+
* var obj = {};
40+
*
41+
* setNonEnumerableProperty( obj, 'foo', 'bar' );
42+
*
43+
* var v = obj.foo;
44+
* // returns 'bar'
45+
*
46+
* var keys = objectKeys( obj );
47+
* // returns []
48+
*/
49+
declare function setNonEnumerableProperty( obj: any, prop: PropertyName, value: any ): void; // tslint:disable-line: max-line-length
50+
51+
52+
// EXPORTS //
53+
54+
export = setNonEnumerableProperty;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 setNonEnumerableProperty = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns `undefined`...
25+
{
26+
setNonEnumerableProperty( {}, 'foo', 'bar' ); // $ExpectType void
27+
}
28+
29+
// The compiler throws an error if the function is provided a second argument which is not a valid property name...
30+
{
31+
setNonEnumerableProperty( {}, true, 'bar' ); // $ExpectError
32+
setNonEnumerableProperty( {}, false, 'bar' ); // $ExpectError
33+
setNonEnumerableProperty( {}, null, 'bar' ); // $ExpectError
34+
setNonEnumerableProperty( {}, undefined, 'bar' ); // $ExpectError
35+
setNonEnumerableProperty( {}, [], 'bar' ); // $ExpectError
36+
setNonEnumerableProperty( {}, {}, 'bar' ); // $ExpectError
37+
setNonEnumerableProperty( {}, ( x: number ): number => x, 'bar' ); // $ExpectError
38+
}
39+
40+
// The compiler throws an error if the function is provided insufficient arguments...
41+
{
42+
setNonEnumerableProperty(); // $ExpectError
43+
setNonEnumerableProperty( {} ); // $ExpectError
44+
setNonEnumerableProperty( {}, 'foo' ); // $ExpectError
45+
}

lib/node_modules/@stdlib/utils/define-nonenumerable-property/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": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 { PropertyName } from '@stdlib/types/object';
24+
25+
/**
26+
* Getter function.
27+
*
28+
* @returns property value
29+
*/
30+
type Getter = () => any;
31+
32+
/**
33+
* Defines a non-enumerable read-only accessor.
34+
*
35+
* ## Notes
36+
*
37+
* - Non-enumerable read-only accessors are non-configurable.
38+
*
39+
* @param obj - object on which to define the property
40+
* @param prop - property name
41+
* @param getter - accessor
42+
*
43+
* @example
44+
* function getter() {
45+
* return 'bar';
46+
* }
47+
*
48+
* var obj = {};
49+
*
50+
* setNonEnumerableReadOnlyAccessor( obj, 'foo', getter );
51+
*
52+
* try {
53+
* obj.foo = 'boop';
54+
* } catch ( err ) {
55+
* console.error( err.message );
56+
* }
57+
*/
58+
declare function setNonEnumerableReadOnlyAccessor( obj: any, prop: PropertyName, getter: Getter ): void; // tslint:disable-line: max-line-length
59+
60+
61+
// EXPORTS //
62+
63+
export = setNonEnumerableReadOnlyAccessor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 setNonEnumerableReadOnlyAccessor = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns `undefined`...
25+
{
26+
setNonEnumerableReadOnlyAccessor( {}, 'foo', (): string => 'bar' ); // $ExpectType void
27+
}
28+
29+
// The compiler throws an error if the function is provided a second argument which is not a valid property name...
30+
{
31+
setNonEnumerableReadOnlyAccessor( {}, true, (): string => 'bar' ); // $ExpectError
32+
setNonEnumerableReadOnlyAccessor( {}, false, (): string => 'bar' ); // $ExpectError
33+
setNonEnumerableReadOnlyAccessor( {}, null, (): string => 'bar' ); // $ExpectError
34+
setNonEnumerableReadOnlyAccessor( {}, undefined, (): string => 'bar' ); // $ExpectError
35+
setNonEnumerableReadOnlyAccessor( {}, [], (): string => 'bar' ); // $ExpectError
36+
setNonEnumerableReadOnlyAccessor( {}, {}, (): string => 'bar' ); // $ExpectError
37+
setNonEnumerableReadOnlyAccessor( {}, ( x: number ): number => x, (): string => 'bar' ); // $ExpectError
38+
}
39+
40+
// The compiler throws an error if the function is provided a third argument which is not a valid getter...
41+
{
42+
setNonEnumerableReadOnlyAccessor( {}, 'foo', '5' ); // $ExpectError
43+
setNonEnumerableReadOnlyAccessor( {}, 'foo', 5 ); // $ExpectError
44+
setNonEnumerableReadOnlyAccessor( {}, 'foo', true ); // $ExpectError
45+
setNonEnumerableReadOnlyAccessor( {}, 'foo', false ); // $ExpectError
46+
setNonEnumerableReadOnlyAccessor( {}, 'foo', null ); // $ExpectError
47+
setNonEnumerableReadOnlyAccessor( {}, 'foo', undefined ); // $ExpectError
48+
setNonEnumerableReadOnlyAccessor( {}, 'foo', [] ); // $ExpectError
49+
setNonEnumerableReadOnlyAccessor( {}, 'foo', {} ); // $ExpectError
50+
}
51+
52+
// The compiler throws an error if the function is provided insufficient arguments...
53+
{
54+
setNonEnumerableReadOnlyAccessor(); // $ExpectError
55+
setNonEnumerableReadOnlyAccessor( {} ); // $ExpectError
56+
setNonEnumerableReadOnlyAccessor( {}, 'foo' ); // $ExpectError
57+
}

lib/node_modules/@stdlib/utils/define-nonenumerable-read-only-accessor/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": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 { PropertyName } from '@stdlib/types/object';
24+
25+
/**
26+
* Defines a non-enumerable read-only property.
27+
*
28+
* ## Notes
29+
*
30+
* - Non-enumerable read-only properties are non-configurable.
31+
*
32+
* @param obj - object on which to define the property
33+
* @param prop - property name
34+
* @param value - value to set
35+
*
36+
* @example
37+
* var obj = {};
38+
*
39+
* setNonEnumerableReadOnly( obj, 'foo', 'bar' );
40+
*
41+
* try {
42+
* obj.foo = 'boop';
43+
* } catch ( err ) {
44+
* console.error( err.message );
45+
* }
46+
*/
47+
declare function setNonEnumerableReadOnly( obj: any, prop: PropertyName, value: any ): void; // tslint:disable-line: max-line-length
48+
49+
50+
// EXPORTS //
51+
52+
export = setNonEnumerableReadOnly;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 setNonEnumerableReadOnly = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns `undefined`...
25+
{
26+
setNonEnumerableReadOnly( {}, 'foo', 'bar' ); // $ExpectType void
27+
}
28+
29+
// The compiler throws an error if the function is provided a second argument which is not a valid property name...
30+
{
31+
setNonEnumerableReadOnly( {}, true, 'bar' ); // $ExpectError
32+
setNonEnumerableReadOnly( {}, false, 'bar' ); // $ExpectError
33+
setNonEnumerableReadOnly( {}, null, 'bar' ); // $ExpectError
34+
setNonEnumerableReadOnly( {}, undefined, 'bar' ); // $ExpectError
35+
setNonEnumerableReadOnly( {}, [], 'bar' ); // $ExpectError
36+
setNonEnumerableReadOnly( {}, {}, 'bar' ); // $ExpectError
37+
setNonEnumerableReadOnly( {}, ( x: number ): number => x, 'bar' ); // $ExpectError
38+
}
39+
40+
// The compiler throws an error if the function is provided insufficient arguments...
41+
{
42+
setNonEnumerableReadOnly(); // $ExpectError
43+
setNonEnumerableReadOnly( {} ); // $ExpectError
44+
setNonEnumerableReadOnly( {}, 'foo' ); // $ExpectError
45+
}

lib/node_modules/@stdlib/utils/define-nonenumerable-read-only-property/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)