是否可以排除已安装依赖项中的全局类型?
我安装了一个本地依赖项.这也复制了该依赖项的node_modules文件夹.此node_modules文件夹保存已安装的@types类型.这些与为主项目安装的@types类型冲突.
例如.project-path/node_modules/local-dependency/node_modules/@types/react与冲突project-path/node_modules/@types/react.
是否有可能使打字稿编译器忽略该局部依赖的输入?
如何增强导出默认值的模块?例如:
默认模块.d.ts
declare namespace TheNamespace {
interface TheInterface {
prop: number
}
}
export default TheNamespace
Run Code Online (Sandbox Code Playgroud)
应用程序.ts
import theModule from "./default-module"
declare module "./default-module" {
interface AugmentedInterface {
augmentedProp: number
}
}
let theNormalVariable: theModule.TheInterface // fine
let theAugmentedVariable: theModule.AugmentedInterface // errors
Run Code Online (Sandbox Code Playgroud)
但是,当您export =而不是 时export default,这似乎工作正常。(正如本期所讨论的)
等于模块.d.ts
declare namespace TheNamespace {
interface TheInterface {
prop: number
}
}
export = TheNamespace
Run Code Online (Sandbox Code Playgroud)
应用程序.ts
import theModule = require("./equals-module")
declare module "./equals-module" {
interface AugmentedInterface {
augmentedProp: …Run Code Online (Sandbox Code Playgroud)