You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would also allow to statically check these scripts before running, e.g. help with rhysd/actionlint#55. This would have prevented plenty of mishaps that I caused…
testing:
steps:
- uses: actions/checkout@v5 # or whichever way you prefer, to access your scripts
- uses: actions/github-script@v8with:
script: | const mod = await import('${{ github.workspace }}/path/to/your/file.ts'); // use mod as you wish
There are some small syntax limitations, that you can configure tsc to catch. Refer to the Node and TypeScript docs for those:
IMO If you read through the limitations, there are plenty of things that will still require proper TS handling.
Could you list out the limitations that are affecting your code? I am particularly wondering what "proper" is in this case. For example, the lack of enum is notable, but the rest of the syntax (namespace etc.) is exceedingly rare in userland code, in my experience.
I often think of tsc as modelling the environment that code runs in. In that sense, erasableSyntaxOnly and verbatimModuleSyntax is fairly scalable, especially for the script cases that actions/github-script is aimed for.
I think there is still the usecase of having the typescript code inline in the action - or can that be achieved as well now?
We've typically been using external script files via the import() pattern above, as a way to get full typecheck/format/lint/test support, without needing to do that against inline YAML. So I haven't personally felt this pain.
To be clear, your usecases may be valid, I don't want to argue them 😌
My usecase is collecting env/build/release information (including some gh api calls) and using that to trigger the api docs generation/diff and push resulting comments. The api docs generation uses TS-AST under the hood to do its job, so it requires a lot of things outside of my control including enums.
Currently, I defer to tsx/tsup/other wrappers + CI switches/overrides to run the ts code for me. Bleeding built-time/actions' constraints into my main code is not acceptable for me. Though I can understand if you consider full TS support a non goal.
The type checking is available with @actions packages.
importtype*ascorefrom'@actions/core'importtype*asgithubfrom'@actions/github'typeGitHubScriptContext={core: typeofcorecontext: typeofgithub.contextgithub: ReturnType<typeofgithub.getOctokit>}exportconstmain=async({ core, context, github }: GitHubScriptContext)=>{// The type checking is available here!core.info('Hello from TypeScript!')awaitgithub.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,issue_number: context.issue.number,body: `Hi`,})}
Note that it needs to set up tsconfig.json to run TypeScript directly in Node.js.
Activity
nomeata commentedon Dec 14, 2023
This would also allow to statically check these scripts before running, e.g. help with rhysd/actionlint#55. This would have prevented plenty of mishaps that I caused…
Flydiverny commentedon Dec 14, 2023
As a PoC I made a wrapper around github-script to use typescript sources https://github.com/Flydiverny/github-typescript it adds a small overhead as it uses esbuild binary to convert into JS.
kf6kjg commentedon Jun 27, 2024
Also the tsx project allows for doing some workarounds, and might lead to a solution here:
In this I'm using tsx's programmatic API to load another file that's typescript.
Only caveat is that it can't find tsx in order to import it... So I'm solving that problem...
cscleison commentedon Jul 4, 2024
@kf6kjg thanks for you suggestion! I managed to make it work with:
kf6kjg commentedon Jul 6, 2024
Just put in #477 with what is unit testing as a functional support for TypeScript!
fpapado commentedon Sep 10, 2025
With the recent v8 release of this action being on Node 24 (and v7 if Node >=22.18.0), one can get TypeScript support out of the box, via Node's native type stripping (which, even though in the "Release candidate" stage, is turned on by default).
So this should work:
There are some small syntax limitations, that you can configure
tscto catch. Refer to the Node and TypeScript docs for those:So I have a hunch that this issue can be closed 😌
nomeata commentedon Sep 10, 2025
I think there is still the usecase of having the typescript code inline in the action - or can that be achieved as well now?
ST-DDT commentedon Sep 10, 2025
IMO If you read through the limitations, there are plenty of things that will still require proper TS handling.
fpapado commentedon Sep 10, 2025
Could you list out the limitations that are affecting your code? I am particularly wondering what "proper" is in this case. For example, the lack of
enumis notable, but the rest of the syntax (namespaceetc.) is exceedingly rare in userland code, in my experience.I often think of
tscas modelling the environment that code runs in. In that sense,erasableSyntaxOnlyandverbatimModuleSyntaxis fairly scalable, especially for the script cases that actions/github-script is aimed for.I got curious about this, and tested it in a small repo. It seems that inline typescript is a no-go :(
We've typically been using external script files via the
import()pattern above, as a way to get full typecheck/format/lint/test support, without needing to do that against inline YAML. So I haven't personally felt this pain.To be clear, your usecases may be valid, I don't want to argue them 😌
ST-DDT commentedon Sep 10, 2025
My usecase is collecting env/build/release information (including some gh api calls) and using that to trigger the api docs generation/diff and push resulting comments. The api docs generation uses TS-AST under the hood to do its job, so it requires a lot of things outside of my control including enums.
Currently, I defer to tsx/tsup/other wrappers + CI switches/overrides to run the ts code for me. Bleeding built-time/actions' constraints into my main code is not acceptable for me. Though I can understand if you consider full TS support a non goal.
int128 commentedon Aug 14, 2026
We can directly import a TypeScript file in actions/github-script. For example,
The type checking is available with
@actionspackages.Note that it needs to set up
tsconfig.jsonto run TypeScript directly in Node.js.Here is an example at https://github.com/int128/github-script-typescript.
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!
refactor: Use TypeScript!