Skip to content

Commit 6dd27c4

Browse files
committed
[New] add types
1 parent 3caee87 commit 6dd27c4

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
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 isGeneratorFunction(fn: unknown): fn is GeneratorFunction;
2+
3+
export = isGeneratorFunction;

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ var getGeneratorFunc = function () { // eslint-disable-line consistent-return
1818
} catch (e) {
1919
}
2020
};
21+
/** @type {undefined | false | null | GeneratorFunctionConstructor} */
2122
var GeneratorFunction;
2223

24+
/** @type {import('.')} */
2325
module.exports = function isGeneratorFunction(fn) {
2426
if (typeof fn !== 'function') {
2527
return false;
@@ -36,7 +38,10 @@ module.exports = function isGeneratorFunction(fn) {
3638
}
3739
if (typeof GeneratorFunction === 'undefined') {
3840
var generatorFunc = getGeneratorFunc();
39-
GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false;
41+
GeneratorFunction = generatorFunc
42+
// eslint-disable-next-line no-extra-parens
43+
? /** @type {GeneratorFunctionConstructor} */ (getProto(generatorFunc))
44+
: false;
4045
}
4146
return getProto(fn) === GeneratorFunction;
4247
};

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"test:uglified": "node test/uglified",
1818
"posttest": "npx npm@\">= 10.2\" audit --production",
1919
"lint": "eslint --ext=js,mjs .",
20+
"postlint": "tsc && attw -P",
2021
"version": "auto-changelog && git add CHANGELOG.md",
2122
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
2223
},
@@ -48,7 +49,12 @@
4849
"safe-regex-test": "^1.1.0"
4950
},
5051
"devDependencies": {
52+
"@arethetypeswrong/cli": "^0.17.2",
5153
"@ljharb/eslint-config": "^21.1.1",
54+
"@ljharb/tsconfig": "^0.2.3",
55+
"@types/for-each": "^0.3.3",
56+
"@types/make-generator-function": "^2.0.3",
57+
"@types/tape": "^5.8.0",
5258
"auto-changelog": "^2.5.0",
5359
"core-js": "^2.6.5 || ^3.20.0",
5460
"encoding": "^0.1.13",
@@ -60,6 +66,7 @@
6066
"nyc": "^10.3.2",
6167
"safe-publish-latest": "^2.0.0",
6268
"tape": "^5.9.0",
69+
"typescript": "next",
6370
"uglify-register": "^1.0.1"
6471
},
6572
"testling": {

test/corejs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
// @ts-ignore
34
require('core-js');
45

56
require('./');

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ test('returns false for non-generator function with faked toString', function (t
5858

5959
test('returns false for non-generator function with faked @@toStringTag', { skip: !hasToStringTag || generatorFuncs.length === 0 }, function (t) {
6060
var generatorFunc = generatorFuncs[0];
61+
/** @type {{ toString(): unknown; valueOf(): unknown; [Symbol.toStringTag]?: unknown; }} */
6162
var fakeGenFunction = {
6263
toString: function () { return String(generatorFunc); },
6364
valueOf: function () { return generatorFunc; }

test/uglified.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
// @ts-ignore
34
require('uglify-register/api').register({
45
exclude: [/\/node_modules\//, /\/test\//],
56
uglify: { mangle: true }

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+
}

0 commit comments

Comments
 (0)