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

Appearance settings

Commit ecae9eb

Browse filesBrowse files
authored
Merge pull request actions#402 from typed-actions/export-types
Expose async-function argument type
2 parents 6b5d3ea + 044ebbb commit ecae9eb
Copy full SHA for ecae9eb

File tree

4 files changed

+42
-2
lines changed
Filter options

4 files changed

+42
-2
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+18Lines 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

Copy file name to clipboardExpand all lines: package.json
+3-1Lines 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

Copy file name to clipboardExpand all lines: src/async-function.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import fetch from 'node-fetch'
88

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

11-
type AsyncFunctionArguments = {
11+
export declare type AsyncFunctionArguments = {
1212
context: Context
1313
core: typeof core
1414
github: InstanceType<typeof GitHub>

‎types/async-function.d.ts

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="node" />
2+
import * as core from '@actions/core';
3+
import * as exec from '@actions/exec';
4+
import { Context } from '@actions/github/lib/context';
5+
import { GitHub } from '@actions/github/lib/utils';
6+
import * as glob from '@actions/glob';
7+
import * as io from '@actions/io';
8+
import fetch from 'node-fetch';
9+
export declare type AsyncFunctionArguments = {
10+
context: Context;
11+
core: typeof core;
12+
github: InstanceType<typeof GitHub>;
13+
exec: typeof exec;
14+
glob: typeof glob;
15+
io: typeof io;
16+
fetch: typeof fetch;
17+
require: NodeRequire;
18+
__original_require__: NodeRequire;
19+
};
20+
export declare function callAsyncFunction<T>(args: AsyncFunctionArguments, source: string): Promise<T>;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.