Expose async-function argument type

We are exposing the async-function argument type for jsDoc
type declaration support. This means that we now could do:
"npm i -D @types/github-script@github:actions/github-script"
and the add:
"@param {import('@types/github-script').AsyncFunctionArguments}
AsyncFunctionArguments".

This could obviously be done in other ways too, like using
"@typed-actions/github-script" instead. But it seems better
to use the actual source repository instead of a third-party
library to import the type declaration.
This commit is contained in:
Viktor Lott
2023-07-03 10:30:03 +02:00
parent 6f00a0b667
commit 56bdc6c318
5 changed files with 197 additions and 2 deletions

View File

@@ -419,6 +419,25 @@ jobs:
await printStuff()
```
### Use scripts with jsDoc support
If you want type support for your scripts, you could use the 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;
};
```
For an alternative setup, please read (alternative-setup)[./docs/alternative-setup.md].
### Use env as input
You can set env vars to use them in your script: