How to overwrite incorrect TypeScript type definition installed via @types/package

You can patch @types/foo locally for your app by patch-package.

  1. Run npm i -D patch-package

  2. Simply modify node_modules/@types/foo to suit your needs.

  3. Run npx patch-package @types/foo. This creates a diff file in patches/ that records the changes made from the last step.

  4. Add "scripts": {"postinstall": "patch-package"} in package.json. This make patches to be applied each time people run npm install.

Leave a Comment