Typescript 可选对等依赖

Typescript 可选对等依赖,typescript,npm,Typescript,Npm,我正在开发一个模块a。用户可以选择将Winston logger注入我的模块,因此Winston是它的对等依赖项 每当我将模块A安装到另一个不想记录东西的模块中(因此我不包括Winston)并尝试tscit时,TS就会大叫 Cannot find module 'winston' or its corresponding type declarations. 我该怎么做呢?自从NPM v7.x以来,您可以使用peerDependenciesMetapackage.json配置,该配置允许 例如

我正在开发一个模块a。用户可以选择将Winston logger注入我的模块,因此
Winston
是它的对等依赖项

每当我将模块A安装到另一个不想记录东西的模块中(因此我不包括Winston)并尝试
tsc
it时,TS就会大叫

Cannot find module 'winston' or its corresponding type declarations.

我该怎么做呢?

自从NPM v7.x以来,您可以使用
peerDependenciesMeta
package.json配置,该配置允许

例如,在您的“模块A”包.json中:

“对等依赖”:{

“winston”:“>1.0.0自NPM v7.x以来,您可以使用
peerDependenciesMeta
package.json配置,该配置允许

例如,在您的“模块A”包.json中:

“对等依赖”:{
“温斯顿”:“>1.0.0