Twoslash-vue is an extension for the Twoslash library, specifically designed to bring its powerful TypeScript language server features to Vue Single File Components (SFCs). It enables rich code insights such as type on hover, compilation errors, and code completions directly within Vue `<script setup>` and `<script>` blocks, as well as the template context when supported by underlying Vue language tools. The current stable version is 0.3.8, and the package maintains a relatively active release cadence, frequently updating to support the latest TypeScript versions (currently ^5.5.0 || ^6.0.0) and integrating with advancements in the `@vue/language-core` library. Its key differentiator is its specialized focus on the complexities of Vue SFCs, providing a robust solution for developers looking to document and explain Vue code with accurate type inference and diagnostics, leveraging the established Twoslash ecosystem rather than being a standalone tool for Vue.
npm install twoslash-vueVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `createTwoSlashFromVueSFC` to process a Vue SFC string and extract Twoslash diagnostics like queries, errors, and completions.
Ensure your project's `typescript` dependency is updated to `^5.5.0 || ^6.0.0` or a compatible version as specified in the package's peer dependencies. Run `npm install typescript@latest` or `yarn add typescript@latest`.
Regularly update `twoslash-vue` and its related dependencies. Consider using a `^` or `~` range for `twoslash-vue` in your `package.json` to receive compatible updates.
Ensure you are using `twoslash-vue` in conjunction with the core `twoslash` library and a suitable renderer. Refer to the main Twoslash documentation for full integration instructions into your documentation pipeline.
Install `typescript` manually: `npm install typescript` or `yarn add typescript`. Verify the installed version meets `twoslash-vue`'s peer dependency requirements (e.g., `^5.5.0 || ^6.0.0`).
Ensure you are using ES Modules syntax: `import { createTwoSlashFromVueSFC } from 'twoslash-vue';`. If you are in a pure CommonJS environment, you might need a bundler or transpile your code.Always pass a unique `.vue` filename as the second argument to `createTwoSlashFromVueSFC`, e.g., `createTwoSlashFromVueSFC(code, 'MyComponent.vue')`.