Skip to content

Commit 42e29a8

Browse files
committed
[New] add types
1 parent 574ee8e commit 42e29a8

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import whichTypedArray from 'which-typed-array';
2+
3+
declare namespace hasTypedArrays {
4+
type TypedArrayName = whichTypedArray.TypedArrayName;
5+
}
6+
7+
declare function hasTypedArrays(): boolean;
8+
9+
export = hasTypedArrays;

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var some = require('array.prototype.some');
44
var whichTypedArray = require('which-typed-array');
55

6+
/** @type {import('.').TypedArrayName[]} */
67
var typedArrays = [
78
'Float32Array',
89
'Float64Array',
@@ -18,7 +19,7 @@ var typedArrays = [
1819
];
1920

2021
module.exports = function hasTypedArrays() {
21-
return some(typedArrays, function (TA) {
22-
return whichTypedArray(new global[TA]());
22+
return some(typedArrays, /** @param {import('.').TypedArrayName} TA */ function (TA) {
23+
return !!whichTypedArray(new global[TA]());
2324
});
2425
};

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"prepublishOnly": "safe-publish-latest",
1313
"prepublish": "not-in-publish || npm run prepublishOnly",
1414
"lint": "eslint --ext=js,mjs .",
15+
"postlint": "tsc && attw -P",
1516
"pretest": "npm run lint",
1617
"tests-only": "nyc tape 'test/**/*.js'",
1718
"test:harmony": "nyc node --harmony --es-staging test",
@@ -48,15 +49,19 @@
4849
},
4950
"homepage": "https://github.com/inspect-js/has-typed-arrays#readme",
5051
"devDependencies": {
52+
"@arethetypeswrong/cli": "^0.17.1",
5153
"@ljharb/eslint-config": "^21.1.1",
54+
"@ljharb/tsconfig": "^0.2.2",
55+
"@types/tape": "^5.6.5",
5256
"auto-changelog": "^2.5.0",
5357
"encoding": "^0.1.13",
5458
"eslint": "=8.8.0",
5559
"in-publish": "^2.0.1",
5660
"npmignore": "^0.3.1",
5761
"nyc": "^10.3.2",
5862
"safe-publish-latest": "^2.0.0",
59-
"tape": "^5.9.0"
63+
"tape": "^5.9.0",
64+
"typescript": "next"
6065
},
6166
"funding": {
6267
"url": "https://github.com/sponsors/ljharb"
@@ -75,7 +80,8 @@
7580
},
7681
"publishConfig": {
7782
"ignore": [
78-
".github/workflows"
83+
".github/workflows",
84+
"types"
7985
]
8086
}
8187
}

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('export', function (t) {
1111
});
1212

1313
test('Typed Arrays', function (t) {
14-
var anyExist = some([
14+
var anyExist = some(/** @type {import('..').TypedArrayName[]} */ [
1515
'Float32Array',
1616
'Float64Array',
1717
'Int8Array',
@@ -23,7 +23,7 @@ test('Typed Arrays', function (t) {
2323
'Uint32Array',
2424
'BigInt64Array',
2525
'BigUint64Array'
26-
], function (TA) {
26+
], /** @param {import('..').TypedArrayName} TA */ function (TA) {
2727
return typeof global[TA] === 'function';
2828
});
2929

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@ljharb/tsconfig",
3+
"compilerOptions": {
4+
"maxNodeModuleJsDepth": 0,
5+
},
6+
"exclude": [
7+
"coverage"
8+
]
9+
}

types/array.prototype.some/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module 'array.prototype.some' {
2+
function some<T>(
3+
arr: T[],
4+
callbackfn: (value: T, index?: number, array?: T[]) => boolean,
5+
thisArg?: unknown,
6+
): boolean;
7+
8+
export = some;
9+
}

0 commit comments

Comments
 (0)