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

后端 未结 4 807
悲哀的现实
悲哀的现实 2020-12-02 08:28

Say that I want to use dotenv module in my TypeScript project and install its .d.ts using npm install @types/dotenv --save. Then I realize that the

4条回答
  •  误落风尘
    2020-12-02 09:07

    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.

提交回复
热议问题