我正在为一个展览完成一个聊天机器人。错误如下:
Error: src/app/services/pusher.service.ts:13:5 - error TS2345: 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'.
13 encrypted: true
~~~~~~~~~~~~~~~
代码:
import { Injectable } from '@angular/core';
import Pusher from 'pusher-js';
// this is here to discourage the instantianting of pusher any where its
// needed, better to reference it from one place
@Injectable()
export class PusherService {
private _pusher: any;
constructor() {
this._pusher = new Pusher ('APP_KEY', {
cluster: 'eu',
encrypted: true
});
}
getPusher() {
return this._pusher;
}
}
嗨,芬坦,欢迎来到stackoverflow!
错误告诉你需要知道的:你提供的选项包括一个"加密"的属性,但它不应该在其中。
我不知道pusher js是关于什么的,但你可以在这里阅读选项的所有可能属性。我在文档中发现了两件事:
首先,您可能需要指定"forceTLS"属性:
this._pusher = new Pusher ('APP_KEY', {
cluster: 'eu',
forceTLS: true
});
其次,您可能想更改导入以使用加密通道:
切换
import Pusher from 'pusher-js';
至
import Pusher from 'pusher-js/with-encryption';
你可以走了。