vue-tsx-support is a TypeScript support library designed to enable and enhance the use of TSX (JSX for TypeScript) within Vue 2 applications. Currently at version 3.2.0, this package primarily functions as a type checker, providing robust type safety for JSX syntax used in Vue 2 components. It is crucial to note that vue-tsx-support does not handle JSX transpilation; users must integrate a separate Babel preset (such as `@vue/babel-preset-jsx`) for this purpose. A key differentiator is its explicit focus on the Vue 2 ecosystem; it does not support Vue 3, which incorporates its own JSX type checking mechanisms that are incompatible. The library supports various component styles, including object-style, class-style (with `vue-class-component`), and `@vue/composition-api`, with specific instructions for each. The project is largely in a maintenance phase, as its core functionality is tied to the now older Vue 2 major version.
npm install vue-tsx-supportVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a type-safe TSX component with props and emitted events using `createTsxComponent` and how to consume it in a parent component, including the necessary global type import.
Consult the official 'Migration from V2' guide in the `vue-tsx-support` README to understand specific API changes and update component definitions and imports accordingly.
For Vue 3 projects, use Vue's built-in JSX/TSX support. Do not attempt to install `vue-tsx-support`. If migrating from Vue 2 to Vue 3, you must remove this package and adjust your JSX setup.
Ensure your project's Babel configuration includes a preset capable of transpiling JSX. For Vue CLI projects, ensure `@vue/babel-preset-app` is installed or add `@vue/babel-preset-jsx` manually.
Update your `tsconfig.json` to include: `"compilerOptions": { "jsx": "preserve", "jsxFactory": "VueTsxSupport" }`. Incorrect settings will lead to TypeScript errors related to JSX.Add `import 'vue-tsx-support/enable-check';` to your main TypeScript entry file (e.g., `main.ts` or `App.tsx`), or add `"node_modules/vue-tsx-support/enable-check.d.ts"` to the `include` array in your `tsconfig.json`.
Verify and update your Babel configuration and presets if you are using `@vue/composition-api` and experiencing issues with JSX/TSX transpilation. Ensure compatible versions are installed.
Ensure `jsxFactory` is set to `"VueTsxSupport"` in `tsconfig.json` AND that `import 'vue-tsx-support/enable-check';` is present in your main entry file, or `node_modules/vue-tsx-support/enable-check.d.ts` is included in your `tsconfig.json`.
Verify that `"jsx": "preserve"` is set in your `tsconfig.json`. Also, check your TSX file for unmatched tags or fragments which require `<>...</>` or `<React.Fragment>...</React.Fragment>` (though Vue JSX typically doesn't use fragments directly like React).
Confirm that `import 'vue-tsx-support/enable-check';` is present in your project's entry point or included in `tsconfig.json`. Also, check your `tsconfig.json`'s `jsxFactory` setting.
Ensure your custom component is wrapped with `createTsxComponent<Props, Events>` and that the event names (e.g., `onClick` for an `@click` emit) are correctly specified in the `Events` interface.