typescript - 排除/覆盖 npm 提供的类型

标签 typescript typescript-typings

我有一个 npm 包,里面写得很糟糕,已经过时了。我已经编写了自己的打字,现在我想知道我是否可以以某种方式从 npm 包中排除原始打字。不是简单的接口(interface)扩展,原来的基本都是垃圾。

使用 tsconfig.json 中的排除列表当然不能用于此目的,因为即使您排除该文件夹,它仍会从 node_modules 加载文件。

最佳答案

在你的src下创建node_modules文件夹,然后把你想要覆盖的模块类型放入里面:

├── node_modules
│   └── ...
│
└── src
    ├── index.ts
    ├── ... your codes ...
    │
    └── node_modules
        └── <module-to-be-overwritten>
            └── index.d.ts

无需修改tsconfig.json中的compilerOptions

阅读 TypeScript 如何解析模块 部分 https://www.typescriptlang.org/docs/handbook/module-resolution.html .

关于typescript - 排除/覆盖 npm 提供的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41627631/

相关文章:

reactjs - 如何在 React 中获取 ChildNode 的宽度?

javascript - React 句柄更改功能无需参数事件即可工作

angular - 如何将对象列表复制到另一个 [Typescript]

angular - Angular 的 HTTP 请求中不包含特定参数

javascript - Http Get- 从 Web api 获取对象

javascript - 开 Jest 比较对象。字符串

typescript - vscode typescript : 'Add all missing imports' shortcut

javascript - 如何将 typescript 类型添加到导出类的 NPM 模块?

node.js - 如何让 Webpack 和 Typescript 使用外部 node_module 文件夹?

typescript - 在 onPress 中 React Native Typescript Formik 的 handleSubmit 类型