The @knighted/jsx compiler plugin and runtime typings let you keep DOM and React tagged templates type-safe without a separate build step. This guide shows the recommended tsconfig layouts for projects that:
- Author DOM helpers with the
jsxtagged template. - Compose React elements through
reactJsx. - Mix the helpers with traditional React components that use the normal JSX transform.
Note
At runtime you still render through the tagged template functions (jsx, reactJsx, or their Node variants). The @knighted/jsx/jsx-runtime entry only exists so TypeScript can validate .tsx helpers when you set jsxImportSource.
Use one tsconfig.json when the whole project can share the same JSX compiler options:
jsxImportSourcepoints TypeScript at the packaged runtime typings so.tsxhelpers get DOM-friendly diagnostics.- The language-service plugin enforces DOM vs React rules for tagged templates in
.tsfiles. Add extra keys intagModesif you aliasjsx/reactJsxto different identifiers. - React components still compile and run through React’s own runtime; the setting only affects type checking. The
reactJsxhelper re-uses React’s intrinsic element typings (props/events/refs), and the@knighted/jsx/reactentry exports helper types if you need explicit annotations in your code.
Larger repos sometimes prefer separate project references. The pattern below keeps React’s default JSX runtime for your main app while opt-ing .tsx helper folders into the @knighted/jsx diagnostics.
// tsconfig.base.json
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
},
}// tsconfig.react.json (default React transform)
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react",
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["src/dom-helpers/**"],
}// tsconfig.jsx-helpers.json (DOM + React tagged templates)
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@knighted/jsx",
"plugins": [
{
"name": "@knighted/jsx-ts-plugin",
"tagModes": {
"jsx": "dom",
"reactJsx": "react",
},
},
],
},
"include": ["src/dom-helpers/**/*.ts", "src/dom-helpers/**/*.tsx"],
}Run tsc --build tsconfig.react.json tsconfig.jsx-helpers.json (or wire both configs into your scripts). Only the helper config needs the plugin; the React build keeps its default runtime semantics.
- Keep
jsxImportSourcescoped to the configs that actually need DOM diagnostics. Standard React components do not require it. reactJsxtagged templates already returnReactElements, so you can mix them into React trees even when the file compiles under the helper config.- When you rename the template tag identifiers, update
tagModesso the plugin continues to associate each tag with the correct mode. - Pair editor diagnostics with
tsc --noEmit(using the same config) to ensure CI surfaces the same errors.
{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "NodeNext", "strict": true, "jsx": "react-jsx", "jsxImportSource": "@knighted/jsx", "plugins": [ { "name": "@knighted/jsx-ts-plugin", "tagModes": { "jsx": "dom", "reactJsx": "react", }, }, ], }, "include": ["src"], }