Tor*_*ann 6 typescript feathersjs typescript-3.6
我从feathers 4.3 和Typescript 3.6 开始,有一个问题是如何为feathers 客户端(浏览器端)正确定义正确的Typescript 类型。
我从https://github.com/feathersjs-ecosystem/feathers-chat-react获取了 react 聊天代码,并将其翻译成 Typescript(大部分是直截了当的)。
在feathers.js 中有客户端的定义:
const client = feathers()
Run Code Online (Sandbox Code Playgroud)
的类型client推断为Application<any>。
当我尝试调用authenticate客户端 ( application.js) 时出现问题:
client.authenticate().catch(() => this.setState({ login: null }))
Run Code Online (Sandbox Code Playgroud)
打字稿告诉我 TS2339: Property 'authenticate' does not exist on type 'Application<any>'
如果我将类型转换为 any,,但我宁愿避免这种情况。
我猜解决方案是将它实例化
const client = feathers<MyApplicationType>()
而不是根本不传递类型参数?
Typescript 类型应该是什么样子或应该如何构造的地方是否有文档?它是客户端上可用的不同服务类型的联合吗?
谢谢你的帮助!
小智 1
尝试npm install --save @feathersjs/authentication-client。我也遇到了同样的 TS 错误,但幸运的是,当我在 docker 容器内旋转羽毛时,我收到了一些额外的类型错误,抱怨找不到模块@feathersjs/authentication-client、@feathersjs/rest-client和@feathersjs/primus-client。安装这 3 个软件包后,类型中包含了验证和重新验证Application。
不确定为什么会修复它,但我认为@feathersjs/client包中存在一些错误配置。