An example of module augmentation working as a library of components with mui v5.
Use this example with:
- Download the project
- Install
npm install
- Install the components library
npm i ../components-library
- Build and preview the project
npx vite build && npx vite preview
or run itnpx vite dev
.
For the module augmentation to work, you need to "import" (not in the module import {Whatever} from ...
sense, but include) the typings somewhere.
What I found I liked the most, was creating a globals.d.ts
file (is can be named in any way, since it looks like ViteJS loads all .d.ts
files.). Inside this file, load the typings containing the module augmentation:
import type {} from 'components-library/dist/types/augmentations.d.ts';
^ This could change if it is a published npm package.
You will now have your library new module augmented typings everywhere in this application.
You can also import these typings in your application entry point, index.ts
or main.ts
.