DEV Community

Discussion on: Create a React component library with Vite and Typescript

Collapse
 
giladl82 profile image
Gilad Lev-Ari

Hi, thanks for the explanation.
I have a small question.
I created a library based on this post, and when trying to use it inside my app, I get no IntelliSense on the component's props.

How do I need to set my d.ts?

Collapse
 
nicolaserny profile image
Nicolas Erny

Hi :) It should generate the types. 🤔
In the vite.config.ts, I use this lib to generate types:
import dts from 'vite-plugin-dts';

plugins: [
react(),
dts({
insertTypesEntry: true,
}),
],

Collapse
 
felixselter profile image
FelixSelter • Edited

Change your libraries package.json from:

"types": "./dist/index.d.ts",
"exports": {
    ".": {
      "import": "./dist/lib.es.js",
      "require": "./dist/lib.umd.js",   
    }
  }
Enter fullscreen mode Exit fullscreen mode

to:

"exports": {
    ".": {
      "import": "./dist/lib.es.js",
      "require": "./dist/lib.umd.js",   
      "types": "./dist/index.d.ts",
    }
  }
Enter fullscreen mode Exit fullscreen mode

It seems like the type field is ignored when theres an export field:
stackoverflow.com/a/76212193/11355399