Automate the creation of type definitions for your Stencil web components.
- React (v19+ natively supports custom elements)
- Vue (v3+)
- Solid
- Svelte
- Preact
Install the @stencil/types-output-target package in your Stencil project as a development dependency:
npm install @stencil/types-output-target --save-devConfigure the output target in your stencil.config.ts file:
import { Config } from '@stencil/core';
import { typesOutputTarget } from '@stencil/types-output-target';
export const config: Config = {
outputTargets: [
typesOutputTarget({
reactTypesPath: 'dist/types',
vueTypesPath: 'dist/types',
solidTypesPath: 'dist/types',
svelteTypesPath: 'dist/types',
preactTypesPath: 'dist/types',
}),
],
};Build your Stencil project to generate the framework-specific type definitions:
npm run buildThe component wrappers will be generated in the specified output directory.
Ensure that your Stencil component library's package.json includes the necessary peer dependencies for the frameworks you are targeting. For example, for React:
"peerDependencies": {
"@types/react": ">=19"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}Your users can now import the generated type definitions in their projects to get type support for your Stencil web components in their chosen framework. For example, in a React project:
import 'your-component-library/react-types';