Skip to content

Commit 570ffdd

Browse files
DEV: Type-check with TypeScript 7 (#43406)
This moves type-checking from Glint's `ember-tsc` to TypeScript 7. TypeScript 7 checks `.gts` and `.gjs` files itself, through `ember-content-mapper`. A full check of core, plugins and themes takes about 15 seconds and 3GB of memory. The Glint build needed an 8GB Node heap and several minutes. - `typescript` is now the TypeScript 7 nightly, and `pnpm lint:types` runs `tsc -b --runExternalCode`. ESLint runs on TypeScript 5.9 through lint-configs, and TypeScript 6 stays only for `@glint/tsserver-plugin`. - Bundled plugins and themes use `@discourse/types` from the workspace and reference the core project. One `tsc -b` run checks core and every plugin, and a core type change no longer needs a package release first. - The published `@discourse/types` works with both TypeScript 6 and 7, so plugins outside this repository can move over when they are ready. - The linting workflow checks that the TypeScript 7 language server resolves core imports from a plugin. - The nightly is pinned to `7.1.0-dev.20260930.4`. Later nightlies fail in seven places in core because of microsoft/TypeScript#64656. - TypeScript 7 reports a few errors that Glint dropped because they landed on generated code. This fixes them. For editors, install the TypeScript 7 extension (`TypeScriptTeam.native-preview`) and Glint 2 (1.4.0 or newer). Both are in the VS Code recommendations and the devcontainer. Editors on VS Code's built-in TypeScript server keep working through `@glint/tsserver-plugin`.
1 parent 28529a6 commit 570ffdd

119 files changed

Lines changed: 1168 additions & 574 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.devcontainer/devcontainer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dbaeumer.vscode-eslint",
3030
"lifeart.vscode-glimmer-syntax",
3131
"typed-ember.glint2-vscode",
32+
"TypeScriptTeam.native-preview",
3233
"stylelint.vscode-stylelint"
3334
]
3435
}

‎.github/workflows/linting.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ jobs:
8787
if: ${{ !cancelled() }}
8888
run: pnpm lint:types
8989

90+
- name: TypeScript language server
91+
if: ${{ !cancelled() }}
92+
run: pnpm --dir=frontend/discourse-types test
93+
9094
- name: Prettier
9195
if: ${{ !cancelled() }}
9296
run: |

‎.github/workflows/publish-types.yml‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,3 @@ jobs:
5858
- name: Publish the package
5959
working-directory: frontend/discourse-types
6060
run: pnpm publish --no-git-checks --tag latest
61-
62-
- name: Wait for the published version to be resolvable
63-
run: |
64-
for i in $(seq 1 30); do
65-
pnpm view "@discourse/types@${package_version}" version && exit 0
66-
echo "Not yet resolvable, waiting..."
67-
sleep 10
68-
done
69-
70-
echo "Timed out waiting for @discourse/types@${package_version} to become resolvable" >&2
71-
exit 1
72-
73-
- name: Bump @discourse/types in workspace package.json files
74-
run: |
75-
git checkout -- frontend/discourse-types/package.json
76-
77-
pnpm update --filter './plugins/**' --filter './themes/**' \
78-
"discourse@npm:@discourse/types@${package_version}"
79-
80-
- name: Open a PR with the bump
81-
env:
82-
GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
83-
run: |
84-
git config --global user.email "[email protected]"
85-
git config --global user.name "discoursebot"
86-
87-
branch="types-bump/${package_version}"
88-
git checkout -b "$branch"
89-
git add -A
90-
91-
if git diff --cached --quiet; then
92-
echo "Nothing to bump, skipping PR"
93-
exit 0
94-
fi
95-
96-
git commit -m "DEV: Bump @discourse/types to ${package_version}"
97-
git push -f origin "$branch"
98-
99-
title="DEV: Bump @discourse/types to ${package_version}"
100-
gh pr create --base main --head "$branch" --title "$title" --body "" ||
101-
gh pr edit "$branch" --title "$title"

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ tmp/
2727
!**/tsconfig.json
2828
**/*.md
2929
**/*.d.ts
30+
**/*.d.*.ts

‎.skills/discourse-writing-typescript/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ file after `bin/lint --fix`** to confirm the placement still reads well.
370370
## Verification (all three, in order)
371371

372372
1. `bin/lint --fix <files>`: clean.
373-
2. `pnpm lint:types` from the **repo root** (composite `ember-tsc -b`): **0 errors**. It
373+
2. `pnpm lint:types` from the **repo root** (composite `tsc -b --runExternalCode`): **0 errors**. It
374374
also surfaces consumer fallout when you tighten a previously loose type (e.g. an untyped
375375
helper's return).
376376
3. `bin/qunit` for the touched files' tests: behavior plus the runtime module-resolution

‎.skills/discourse-writing-typescript/references/js-to-ts-conversion.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ primitive with dozens of consumers gets its own.
155155

156156
## The runtime pitfall (the one that bites)
157157

158-
**`ember-tsc` does NOT catch runtime module-resolution errors in non-`@ts-check` `.js`/`.gjs`
158+
**`tsc` does NOT catch runtime module-resolution errors in non-`@ts-check` `.js`/`.gjs`
159159
consumers.** When you rename `x.gjs` to `x.gts`, any consumer that imported it with the
160160
**explicit old extension**
161161

‎.vscode/extensions.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dbaeumer.vscode-eslint",
77
"lifeart.vscode-glimmer-syntax",
88
"typed-ember.glint2-vscode",
9+
"TypeScriptTeam.native-preview",
910
"stylelint.vscode-stylelint",
1011
]
1112
}

‎docs/developer-guides/docs/03-code-internals/27-types.md‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Types whose meaning a runtime test can't capture (a generic's resolved type, an
2626

2727
- **CLI**: Run `pnpm lint:types`
2828

29-
- **VSCode**: Install the [Glint v2](https://marketplace.visualstudio.com/items?itemName=typed-ember.glint2-vscode) extension. This is part of our [recommended config](https://github.com/discourse/discourse/blob/main/.vscode/extensions.json), so you may already have it. If anything isn't working, you may need to trigger "Restart extension host" from VSCode's command palette, or restart the IDE.
29+
- **VSCode**: Install the [TypeScript 7](https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.native-preview) and [Glint v2](https://marketplace.visualstudio.com/items?itemName=typed-ember.glint2-vscode) extensions. Glint 1.4.0 and newer hands `.gts`/`.gjs` files to TypeScript's own language server. Both are part of our [recommended config](https://github.com/discourse/discourse/blob/main/.vscode/extensions.json), so you may already have it. If anything isn't working, you may need to trigger "Restart extension host" from VSCode's command palette, or restart the IDE.
3030

3131
- **JetBrains** (RubyMine, WebStorm, Intellij, etc.): Install the [EmberExperimental](https://plugins.jetbrains.com/plugin/15499-emberexperimental-js) plugin.
3232

@@ -38,22 +38,13 @@ Ensure that you've run `pnpm install` recently
3838

3939
Official themes/plugins, and the official skeletons, are all wired up for types. To enable it for your own plugin/theme, pull in the latest changes from the relevant skeleton (`package.json`, `tsconfig.json`)
4040

41-
## Live type updates for bundled plugins and themes
41+
## Bundled plugins and themes
4242

43-
If you're adding or changing core types and need to use those changes immediately in a bundled plugin or theme, use live type updates.
43+
Plugins and themes in this repository depend on `@discourse/types` through the pnpm workspace and reference the core project from their `tsconfig.json`. `pnpm lint:types` builds core first, so a core type change is checked against every bundled plugin in the same run, with no release or version bump in between.
4444

45-
To do so, temporarily change the plugin or theme's `package.json` to:
45+
In the editor, the TypeScript 7 language server resolves core imports straight to core source. Editors still on TypeScript 6 read the declarations that the last `pnpm lint:types` emitted, so run it, or keep `pnpm types:watch` running, after changing core types.
4646

47-
```json
48-
{
49-
"private": true,
50-
"dependencies": {
51-
"discourse": "workspace:@discourse/types@*"
52-
}
53-
}
54-
```
55-
56-
Then run `pnpm install` and start the type watcher with `pnpm types:watch`.
47+
External plugins and themes consume the published `@discourse/types` package. It is published from `main` by the `publish-types` workflow.
5748

5849
## Relative imports
5950

‎docs/developer-guides/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"lint:fix": "prettier --write '**/*.{md,json,mjs,yml}'"
77
},
88
"devDependencies": {
9-
"@discourse/lint-configs": "^3.8.0",
9+
"@discourse/lint-configs": "^3.8.2",
1010
"prettier": "3.8.1"
1111
}
1212
}

‎eslint.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default [
1818
"spec/",
1919
"frontend/discourse/dist/",
2020
"**/*.d.ts",
21+
"**/*.d.*.ts",
2122
"frontend/discourse-types/external-types",
2223
"frontend/discourse-types/dts-generator.{js,ts}",
2324
"tmp/",

0 commit comments

Comments
 (0)