Skip to content

Commit 41cb419

Browse files
committed
add types
1 parent b8576fe commit 41cb419

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare function isSharedArrayBuffer(obj: unknown): obj is SharedArrayBuffer;
2+
3+
export = isSharedArrayBuffer;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var callBound = require('call-bind/callBound');
44

55
var $byteLength = callBound('SharedArrayBuffer.prototype.byteLength', true);
66

7+
/** @type {import('.')} */
78
module.exports = $byteLength
89
? function isSharedArrayBuffer(obj) {
910
if (!obj || typeof obj !== 'object') {

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"prepublishOnly": "safe-publish-latest",
2222
"prepublish": "not-in-publish || npm run prepublishOnly",
2323
"lint": "eslint --ext=.js,.mjs .",
24+
"postlint": "tsc -p .",
2425
"pretest": "npm run lint",
2526
"tests-only": "nyc tape 'test/**/*.js'",
2627
"test": "npm run tests-only --",
@@ -47,6 +48,12 @@
4748
"homepage": "https://github.com/inspect-js/is-shared-array-buffer#readme",
4849
"devDependencies": {
4950
"@ljharb/eslint-config": "^21.1.0",
51+
"@types/call-bind": "^1.0.5",
52+
"@types/es-value-fixtures": "^1.4.4",
53+
"@types/for-each": "^0.3.3",
54+
"@types/node": "^20.11.19",
55+
"@types/object-inspect": "^1.8.4",
56+
"@types/tape": "^5.6.4",
5057
"aud": "^2.0.4",
5158
"auto-changelog": "^2.4.0",
5259
"available-typed-arrays": "^1.0.7",
@@ -58,7 +65,8 @@
5865
"nyc": "^10.3.2",
5966
"object-inspect": "^1.13.1",
6067
"safe-publish-latest": "^2.0.0",
61-
"tape": "^5.7.5"
68+
"tape": "^5.7.5",
69+
"typescript": "next"
6270
},
6371
"auto-changelog": {
6472
"output": "CHANGELOG.md",

test/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ var isSharedArrayBuffer = require('..');
1111
test('isSharedArrayBuffer', function (t) {
1212
t.equal(typeof isSharedArrayBuffer, 'function', 'is a function');
1313

14-
var nonSABs = v.primitives.concat(v.objects);
14+
// @ts-expect-error TS sucks with concat
15+
var nonSABs = [].concat(v.primitives, v.objects);
1516
forEach(nonSABs, function (nonSAB) {
1617
t.equal(isSharedArrayBuffer(nonSAB), false, inspect(nonSAB) + ' is not a SharedArrayBuffer');
1718
});
1819

1920
t.test('actual SharedArrayBuffer instances', { skip: typeof SharedArrayBuffer === 'undefined' }, function (st) {
20-
var sab = new SharedArrayBuffer();
21+
var sab = new SharedArrayBuffer(0);
2122

2223
st.equal(isSharedArrayBuffer(sab), true, inspect(sab) + ' is a SharedArrayBuffer');
2324

tsconfig.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig to read more about this file */
4+
5+
/* Projects */
6+
7+
/* Language and Environment */
8+
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
9+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
10+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
11+
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
12+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
13+
14+
/* Modules */
15+
"module": "commonjs", /* Specify what module code is generated. */
16+
// "rootDir": "./", /* Specify the root folder within your source files. */
17+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
18+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
19+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
20+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
21+
"typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */
22+
"resolveJsonModule": true, /* Enable importing .json files. */
23+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
24+
25+
/* JavaScript Support */
26+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
27+
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
28+
"maxNodeModuleJsDepth": 0, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
29+
30+
/* Emit */
31+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
32+
"declarationMap": true, /* Create sourcemaps for d.ts files. */
33+
"noEmit": true, /* Disable emitting files from a compilation. */
34+
35+
/* Interop Constraints */
36+
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
37+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
38+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
39+
40+
/* Type Checking */
41+
"strict": true, /* Enable all strict type-checking options. */
42+
43+
/* Completeness */
44+
//"skipLibCheck": true /* Skip type checking all .d.ts files. */
45+
},
46+
"exclude": [
47+
"coverage"
48+
]
49+
}

0 commit comments

Comments
 (0)