我正在使用 dialogflow npm 包,不同于actions-on-google或 googleapis包。
dialogflow 包没有自己的类型定义。因此,我一直在使用@types/dialogflow打包在一起。
最近,类型定义包(@types/dialogflow)更新自v0.11.0至 v4.0.4 ,这是现在的最新版本,包装上写着
This is a stub types definition. dialogflow provides its own type definitions, so you do not need this installed.
但是dialogflow npm包好像没有给出类型定义。 TS 编译器一直说
Could not find a declaration file for module 'dialogflow'. '....js' implicitly has an 'any' type. Try
npm install @types/dialogflow
if it exists or add a new declaration (.d.ts) file containingdeclare module 'dialogflow';
ts(7016)
这个类型定义包有什么问题?
最佳答案
据我所知,dialogflow 尚未发布其类型。没有问题,它们甚至没有列在 this ticket 上。跟踪谷歌 API 类型定义。 (引用自here)
This PR已弃用的 @types/dialogflow
没有添加任何相关链接以表明它们是 native 包含的。
同时,我会在你的 json 包中添加固定版本的 @types/dialogflow
npm install @types/dialogflow@0.11.0
该版本似乎是弃用前的最后一个版本
更新
另一个选项 according to this PR就是尝试这样导入
import * as dialogflow from "dialogflow/protos/protos"
并验证 dialogflow
上的类型 - 也许您可能需要做一些返工
关于typescript - @types/dialogflow 包说 "dialogflow provides its own type definitions"但似乎不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59366832/