Skip to content

Commit bf576db

Browse files
committed
add types
1 parent 4aa150f commit bf576db

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

index.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Determines the type of the given collection, or returns false.
3+
*
4+
* @param {unknown} value The potential collection
5+
* @returns {'Map' | 'Set' | 'WeakMap' | 'WeakSet' | false} 'Map' | 'Set' | 'WeakMap' | 'WeakSet' | false
6+
*/
7+
declare function whichCollection<K, V>(value: Map<K, V>): 'Map';
8+
declare function whichCollection<T>(value: Set<T>): 'Set';
9+
declare function whichCollection<K extends WeakKey, V>(value: WeakMap<K, V>): 'WeakMap';
10+
declare function whichCollection<T extends WeakKey>(value: WeakSet<T>): 'WeakSet';
11+
declare function whichCollection(value: null | undefined | boolean | number | bigint | symbol | unknown): false;
12+
13+
export = whichCollection;

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var isSet = require('is-set');
55
var isWeakMap = require('is-weakmap');
66
var isWeakSet = require('is-weakset');
77

8-
module.exports = function whichCollection(value) {
8+
/** @type {import('.')} */
9+
module.exports = function whichCollection(/** @type {unknown} */ value) {
910
if (value && typeof value === 'object') {
1011
if (isMap(value)) {
1112
return 'Map';

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"prepublish": "not-in-publish || npm run prepublishOnly",
1515
"lint": "eslint --ext=js,mjs .",
1616
"pretest": "npm run lint",
17+
"postlint": "tsc -p . && attw -P",
1718
"tests-only": "nyc tape 'test/**/*.js'",
1819
"test": "npm run tests-only",
1920
"posttest": "npx aud --production",
@@ -42,7 +43,11 @@
4243
},
4344
"homepage": "https://github.com/inspect-js/which-collection#readme",
4445
"devDependencies": {
46+
"@arethetypeswrong/cli": "^0.15.0",
4547
"@ljharb/eslint-config": "^21.1.0",
48+
"@types/for-each": "^0.3.3",
49+
"@types/object-inspect": "^1.8.4",
50+
"@types/tape": "^5.6.4",
4651
"aud": "^2.0.4",
4752
"auto-changelog": "^2.4.0",
4853
"eslint": "=8.8.0",
@@ -52,7 +57,8 @@
5257
"nyc": "^10.3.2",
5358
"object-inspect": "^1.13.1",
5459
"safe-publish-latest": "^2.0.0",
55-
"tape": "^5.7.5"
60+
"tape": "^5.7.5",
61+
"typescript": "next"
5662
},
5763
"dependencies": {
5864
"is-map": "^2.0.3",

tsconfig.json

+49
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)