【发布时间】:2021-07-01 03:42:18
【问题描述】:
我最近一直在尝试习惯使用 Typescript。我注意到每次我安装一个包并使用它时,某些道具会让 Typescript 对我尖叫,说它在包的开发人员所做的界面中不存在。
这里举个例子,我安装了Pusher-js,然后这样实现;
var pusher = new Pusher("API_KEY", {
cluster: "ap1",
encrypted: true,
});
那么加密道具就会报错:
Argument of type '{ cluster: string; encrypted: boolean; }' is not assignable to parameter of type 'Options'.
Object literal may only specify known properties, and 'encrypted' does not exist in type 'Options'.ts(2345)
所以我去了Pusher-js node_modules中的options.d.ts,确定界面中没有定义足够的加密。我想我可以编辑那个,但很明显,当我更新我的包时它会被覆盖。
我的第一个想法是 Pusher-js 开发人员一定错过了这一点,但后来我安装了另一个不同的包,并且出现了同样的问题。某些道具不见了!所以我的打字稿设置一定有问题,而且我现在完全不知所措,因为我刚开始学习打字稿。遇到此类问题的一般做法是什么?
【问题讨论】:
标签: reactjs typescript pusher