Skip to content

Commit

Permalink
Merge pull request #402 from typed-actions/export-types
Browse files Browse the repository at this point in the history
Expose async-function argument type
  • Loading branch information
joshmgross committed Nov 8, 2023
2 parents 6b5d3ea + 044ebbb commit ecae9eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -419,6 +419,24 @@ jobs:
await printStuff()
```

### Use scripts with jsDoc support

If you want type support for your scripts, you could use the command below to install the
`github-script` type declaration.
```sh
$ npm i -D @types/github-script@github:actions/github-script
```

And then add the `jsDoc` declaration to your script like this:
```js
// @ts-check
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
export default async ({ core, context }) => {
core.debug("Running something at the moment");
return context.actor;
};
```

### Use env as input

You can set env vars to use them in your script:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -5,9 +5,11 @@
"author": "GitHub",
"license": "MIT",
"main": "dist/index.js",
"types": "types/async-function.d.ts",
"private": true,
"scripts": {
"build": "ncc build src/main.ts",
"build": "npm run build:types && ncc build src/main.ts",
"build:types": "tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types",
"format:check": "prettier --check src __test__",
"format:write": "prettier --write src __test__",
"lint": "eslint src __test__",
Expand Down
2 changes: 1 addition & 1 deletion src/async-function.ts
Expand Up @@ -8,7 +8,7 @@ import fetch from 'node-fetch'

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

type AsyncFunctionArguments = {
export declare type AsyncFunctionArguments = {
context: Context
core: typeof core
github: InstanceType<typeof GitHub>
Expand Down
20 changes: 20 additions & 0 deletions types/async-function.d.ts
@@ -0,0 +1,20 @@
/// <reference types="node" />
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import { Context } from '@actions/github/lib/context';
import { GitHub } from '@actions/github/lib/utils';
import * as glob from '@actions/glob';
import * as io from '@actions/io';
import fetch from 'node-fetch';
export declare type AsyncFunctionArguments = {
context: Context;
core: typeof core;
github: InstanceType<typeof GitHub>;
exec: typeof exec;
glob: typeof glob;
io: typeof io;
fetch: typeof fetch;
require: NodeRequire;
__original_require__: NodeRequire;
};
export declare function callAsyncFunction<T>(args: AsyncFunctionArguments, source: string): Promise<T>;

0 comments on commit ecae9eb

Please sign in to comment.