错误 TS2345:类型为"{ cluster: string; 加密: 布尔值; }"的参数不可分配给类型为"选项"的参数



我正在为一个展览完成一个聊天机器人。错误如下:

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';

你可以走了。

相关内容

最新更新