Skip to content

NXT-20954: Added custom typecheck for Typescript 7 - #405

Open
daniel-stoian-lgp wants to merge 6 commits into
developfrom
feature/NXT-20954
Open

daniel-stoian-lgp wants to merge 6 commits into
developfrom
feature/NXT-20954

Conversation

@daniel-stoian-lgp

@daniel-stoian-lgp daniel-stoian-lgp commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • I have run automated testing and it is passed
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

Follow-up to the TypeScript 6/7 support change (#404 ). That change lets TypeScript 7 apps build, but skips type checking for them entirely. fork-ts-checker-webpack-plugin needs the JS compiler API (createProgram), and TypeScript 7 doesn't ship it. As a result, type errors in TS 7 apps don't show up in enact pack / enact serve.

This PR adds type checking for TypeScript 7 apps by running the tsc binary that TS 7 ships.

Resolution

  • New config/TypeScriptCheckPlugin.js: a webpack plugin that runs tsc --project tsconfig.json --noEmit --skipLibCheck --incremental --pretty false with Node. Build info goes to node_modules/.cache/tsconfig.tsbuildinfo, the same file fork-ts-checker used.

    • tsc starts each time webpack starts compiling (run / watchRun) and runs while webpack bundles.
    • When webpack finishes compiling (afterCompile), the plugin waits for tsc and adds each diagnostic to the compilation as an error. Existing error output, exit code 1 on failure and the dev-server overlay all work without other changes.
    • With TSC_COMPILE_ON_ERROR=true, diagnostics are added as warnings instead, as with the existing checker plugin.
    • Diagnostics in test and setup files (__tests__, *.spec.* / *.test.*, src/setupProxy.*, src/setupTests.*) are skipped, matching fork-ts-checker's filters.
    • Child compilations (e.g. html-webpack-plugin's) are ignored.
    • If tsc can't run, the build gets a warning instead of failing.
    • A tsc run still in progress is stopped when a watch or serve session ends.
  • config/webpack.config.js: resolveLegacyTypeScript() becomes resolveTypeScript(). It returns {typescriptPath} when the app's typescript package has createProgram (TS 5/6, still handled by fork-ts-checker). Otherwise it returns {tscPath} from the package's bin field (TS 7, handled by the new plugin). The skip warning now only appears when typescript can't be resolved at all.

Additional Considerations

Test scenario

Setup:

  1. Check out this branch of cli and link it globally (npm link inside cli), so enact runs this branch.
  2. cd samples/tutorial-typescript && npm install (installs typescript@^7.0.2).
  3. Add a deliberate type error at the end of src/views/MainPanel.tsx:
    const typeErrorProbe: number = 'not a number';
    export {typeErrorProbe};

TypeScript 7 (new TypeScriptCheckPlugin)

  1. Run enact pack.
    • Expected: Failed to compile. with src/views/MainPanel.tsx(20,7) and TS2322: Type 'string' is not assignable to type 'number'.; exit code 1.
  2. Run enact pack -p.
    • Expected: same error; exit code 1.
  3. Run TSC_COMPILE_ON_ERROR=true enact pack (PowerShell: $env:TSC_COMPILE_ON_ERROR='true'; enact pack).
    • Expected: build succeeds; TS2322 is shown as a warning; exit code 0.
  4. Run enact serve and open the app in the browser.
    • Expected: TS2322 in the terminal and in the browser error overlay.
  5. While serving, change the line to const typeErrorProbe: number = 42; and save.
    • Expected: rebuild shows Compiled successfully! and the overlay disappears.
  6. Stop serve and run enact pack -p.
    • Expected: build succeeds; exit code 0.

TypeScript 6 regression (still uses fork-ts-checker-webpack-plugin)

  1. Put the type error back, run npm install --no-save typescript@6, then run enact pack.
    • Expected: error reported with a code frame (> 20 | const typeErrorProbe ...); exit code 1.
  2. Remove the type error and run enact pack.
    • Expected: build succeeds.

Links

NXT-20954

Comments

Enact-DCO-1.0-Signed-off-by: Daniel Stoian (daniel.stoian@lgepartner.com)

const pluginName = 'EnactTypeScriptCheckPlugin';

// Diagnostics are not reported for test and setup files, matching the fork-ts-checker issue filters.
const excludeFile = /(^|[\\/])__tests__[\\/]|\.(spec|test)\.[^\\/]+$|[\\/]src[\\/]setup(Proxy|Tests)\.[^\\/]+$/;

@dan-ichim-lgp dan-ichim-lgp Oct 21, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/setupTests.ts and src/setupProxy.* are not excluded when tsc prints a relative path.


cancel () {
if (this.child) {
this.child.kill();

@dan-ichim-lgp dan-ichim-lgp Oct 21, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tsc process stopped on Windows is not treated as cancelled. (optional)

Comment thread config/webpack.config.js
}),
// TypeScript 7+ type checking via the tsc binary
tscPath &&
new TypeScriptCheckPlugin({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScriptCheckPlugin is registered before ESLintPlugin and pushes its diagnostic during afterCompile. In enact serve, createCompiler keeps only errors[0], so an ESLint error from the same compilation is dropped from the terminal and the overlay when a type error is also present. enact pack still prints every error. Worth confirming this is acceptable, since on TypeScript 5/6 fork-ts-checker reports asynchronously and does not take that first slot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants