Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitecae9eb

Browse files
authored
Merge pull requestactions#402 from typed-actions/export-types
Expose async-function argument type
2 parents6b5d3ea +044ebbb commitecae9eb

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

‎README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@ jobs:
419419
await printStuff()
420420
```
421421

422+
### Use scripts with jsDoc support
423+
424+
If you want type support for your scripts, you could use the command below to install the
425+
`github-script`type declaration.
426+
```sh
427+
$ npm i -D @types/github-script@github:actions/github-script
428+
```
429+
430+
And then add the `jsDoc` declaration to your script like this:
431+
```js
432+
// @ts-check
433+
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
434+
export default async ({ core, context }) => {
435+
core.debug("Running something at the moment");
436+
return context.actor;
437+
};
438+
```
439+
422440
### Use env as input
423441

424442
You can set env vars to use them in your script:

‎package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"author":"GitHub",
66
"license":"MIT",
77
"main":"dist/index.js",
8+
"types":"types/async-function.d.ts",
89
"private":true,
910
"scripts": {
10-
"build":"ncc build src/main.ts",
11+
"build":"npm run build:types && ncc build src/main.ts",
12+
"build:types":"tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types",
1113
"format:check":"prettier --check src __test__",
1214
"format:write":"prettier --write src __test__",
1315
"lint":"eslint src __test__",

‎src/async-function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import fetch from 'node-fetch'
88

99
constAsyncFunction=Object.getPrototypeOf(async()=>null).constructor
1010

11-
typeAsyncFunctionArguments={
11+
exportdeclaretypeAsyncFunctionArguments={
1212
context:Context
1313
core:typeofcore
1414
github:InstanceType<typeofGitHub>

‎types/async-function.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="node" />
2+
import*ascorefrom'@actions/core';
3+
import*asexecfrom'@actions/exec';
4+
import{Context}from'@actions/github/lib/context';
5+
import{GitHub}from'@actions/github/lib/utils';
6+
import*asglobfrom'@actions/glob';
7+
import*asiofrom'@actions/io';
8+
importfetchfrom'node-fetch';
9+
exportdeclaretypeAsyncFunctionArguments={
10+
context:Context;
11+
core:typeofcore;
12+
github:InstanceType<typeofGitHub>;
13+
exec:typeofexec;
14+
glob:typeofglob;
15+
io:typeofio;
16+
fetch:typeoffetch;
17+
require:NodeRequire;
18+
__original_require__:NodeRequire;
19+
};
20+
exportdeclarefunctioncallAsyncFunction<T>(args:AsyncFunctionArguments,source:string):Promise<T>;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp