如何正确定义羽毛客户端的Typescript类型

问题描述 投票:4回答:1

我首先使用羽毛4.3和Typescript 3.6,并且有一个问题,如何为羽毛客户端(浏览器端)正确定义正确的Typescript类型。

我已经从https://github.com/feathersjs-ecosystem/feathers-chat-react中获取了反应聊天代码,并将其翻译为Typescript(通常是直接的)。

[feathers.js中有一个客户端的定义:

const client = feathers()

client的类型被推断为Application<any>

当我尝试在客户端(authenticate)上调用application.js时出现问题:

client.authenticate().catch(() => this.setState({ login: null }))

打字稿告诉我TS2339: Property 'authenticate' does not exist on type 'Application<any>'

如果我将类型强制转换为any,则可以,但是我宁愿避免这种情况。

我想解决方案是将其实例化为const client = feathers<MyApplicationType>()而不是根本不传递类型参数?

在某处有文档,该Typescript类型应该是什么样子或应该如何构造?它是客户端上可用的不同服务类型的组合吗?

感谢您的帮助!

typescript feathersjs typescript-3.6
1个回答
0
投票

尝试npm install --save @feathersjs/authentication-client。我遇到了同样的TS错误,但是幸运的是,一旦我在docker容器中旋转了羽毛,我又遇到了一些其他类型的错误,抱怨找不到模块@feathersjs/authentication-client@feathersjs/rest-client@feathersjs/primus-client。安装完这3个程序包后,Application类型中包括了authenticate和reAuthenticate。

不确定为什么要修复它,但是我认为@feathersjs/client程序包中存在一些错误配置。

© www.soinside.com 2019 - 2024. All rights reserved.