Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add TypeScript type check #989

Merged
merged 15 commits into from
Dec 19, 2024
27 changes: 27 additions & 0 deletions .github/workflows/typescript-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Check TypeScript types

on:
push:
branches:
- main
- 'release/**'
- 'feature/**'
pull_request:
branches:
- main
- 'release/**'
- 'feature/**'

jobs:
typescript-check:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Check TypeScript types
run: python tools/check_typescript_ci.py

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export function DashboardPlugin({
widget: VariableDefinition;
}) => {
const { id: widgetId, name, type } = widget;
if (type === dh.VariableType.TABLE || type === dh.VariableType.FIGURE) {
if (
type === 'dh.VariableType.TABLE' ||
type === 'dh.VariableType.FIGURE'
) {
wusteven815 marked this conversation as resolved.
Show resolved Hide resolved
// Just ignore table and figure types - only want interesting other types
return;
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/ui/src/js/src/elements/UITable/UITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ export function UITable({
if (alwaysFetchColumnsArray[0] === false) {
return [];
}
return alwaysFetchColumnsArray.filter(v => typeof v === 'string');
return alwaysFetchColumnsArray.filter(
v => typeof v === 'string'
) as string[];
}, [alwaysFetchColumnsArray, modelColumns]);

const mouseHandlers = useMemo(
Expand Down
38 changes: 38 additions & 0 deletions tools/check_typescript_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from re import fullmatch
from subprocess import run
from sys import exit


def main():
print("Checking TypeScript types...")
res = run(
["npx", "tsc", "-p", ".", "--emitDeclarationOnly", "false", "--noEmit"],
capture_output=True,
)

if res.returncode == 0:
return 0

errors = []
for line in res.stdout.decode("utf-8").splitlines():
if len(line) == 0:
continue
if line[0] == " " and len(errors) > 0:
wusteven815 marked this conversation as resolved.
Show resolved Hide resolved
errors[-1] += "\n" + line
else:
errors.append(line)

for err in errors:
match = fullmatch(r"(.+?)\((\d+),(\d+)\): ([\s\S]+)", err)
if match is None:
continue

file, line, col, msg = match.groups()
msg = msg.replace("\n", "%0A")
print(f"::error file={file},line={line},col={col}::{msg}")

return res.returncode


if __name__ == "__main__":
exit(main())
Loading