Editor support and type checking
Components stay ordinary HTML files. The TypeScript in their <script type="text/typescript">
blocks gets completion, hover, diagnostics, go-to-definition, find references and rename from
fuzor-language-tools, a Volar plugin for the TypeScript language
service. Markup keeps your editor's own HTML support. The same package runs in your terminal as
fuzor-tsc, which type-checks a project's TypeScript and HTML components together.
What the editor understands
Each .html file is one TypeScript module, as it is in the build:
- imports and exports of every TypeScript block share the file's module scope, so a component's
exports are importable from other components and
.tsfiles (import { formatCount } from "./counter.html"), and go-to-definition, find references and rename work across them; - the rest of each block is its instance code, typed with the names a component script receives:
host(HTMLElement),signal(AbortSignal),onCleanupand thefuzorintrinsics, with server scripts typed againstfuzor/server; - the module rules appear as diagnostics
where the build would refuse the code: an export that uses an instance-only name, two blocks
importing different things under one name, client code using a server script's import (and the
reverse), and a leftover
langattribute.
Projects opt in through tsconfig.json: its include must list the HTML components. New apps
from create-fuzor already do this:
{
"compilerOptions": { "moduleResolution": "Bundler", "noEmit": true, "allowImportingTsExtensions": true, "strict": true },
"include": ["client/**/*.ts", "components/**/*.html", "pages/**/*.html"]
}
Type checking in the terminal and CI
pnpm add -D fuzor-language-tools
pnpm exec fuzor-tsc # reads ./tsconfig.json
pnpm exec fuzor-tsc -p app/tsconfig.json
fuzor-tsc reports TypeScript's diagnostics and Fuzor's with file, line and column, emits
nothing, and exits 1 when it found an error (2 for bad usage). New apps run it as
npm run typecheck.
VS Code
The Fuzor extension for VS Code (zelavis.fuzor, packages/vscode in the Fuzor repository) needs no settings. It
registers the plugin with VS Code's built-in TypeScript support for HTML files, colours
type="text/typescript" blocks as TypeScript, makes rename inside a block a TypeScript rename
across files (VS Code's HTML support would otherwise rename within the one file), and keeps VS
Code's HTML formatter as the default formatter for HTML. Markup keeps VS Code's built-in HTML
completion, hover and formatting. Install it from the
Visual Studio Marketplace
(search for Fuzor in the Extensions view), or from a terminal:
code --install-extension zelavis.fuzor
VS Code uses its bundled TypeScript 6 unless you select the workspace version, which must also be
TypeScript 6. Uninstall with code --uninstall-extension zelavis.fuzor.
Other editors
The plugin runs inside the TypeScript language service (tsserver), so it works in editors whose
TypeScript support is tsserver. Add it to compilerOptions.plugins and let the editor send HTML
files to its TypeScript client:
{ "compilerOptions": { "plugins": [{ "name": "fuzor-language-tools" }] } }
The plugin is tested against tsserver itself, the service those editors run; individual editors'
settings for sending .html files to their TypeScript client are not covered by Fuzor's tests.
The editor must use the project's TypeScript (version 6), so the plugin is resolved from the
project's node_modules.
Limits
- TypeScript 6 only. TypeScript 7 (the native compiler) has no plugin API yet;
fuzor-tscrefuses it with a message, and editors fall back to plain HTML. - No ESLint integration for HTML components.
- JavaScript blocks (
<script>or<script type="module">) keep the editor's built-in JavaScript support and are not type-checked. - Markdown pages are not checked.
- As in HTML itself, a literal
</script>inside a string ends the block. - In VS Code, a hover inside a block can show a second, single-file card from VS Code's HTML support next to the TypeScript one.