uicomponent.getRoutor show show tyspercript错误:不安全返回AN' any'键入值
我最近在我的SAPUI5项目中添加了TypeScript,并在类型的ESLINT消息上遇到问题。
这个很小的代码显示了错误“任何键入值的不安全返回”,但我不知道原因。 此功能中的所有内容都有类型。 这是uicomponent.getRoutorfor的描述,来自packem @sapui5/ts-types-esm:
有人可以告诉我我在做什么错吗?类型正确吗?
I recently added TypeScript to my SAPUI5 project and having problems with the ESLint messages for the types.
This tiny piece of code shows the error "Unsafe return of an any typed value" but I cannot figure out why.
Everything in this function has a type.
This is the description for UIComponent.getRouterFor from the package @sapui5/ts-types-esm:
Can someone tell me what I am doing wrong? Are the types correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
您正在使用哪种版本的UI5类型和ESLINT?当我在
basecontroller
中编写相同的代码时,我会看到另一个问题:@typescript-eslint/no-no-unnnneconce--type-assertion
,它将自动固定为:
由于推断的类型,不应有必要的铸造。
顺便说一句:就我而言,我正在使用ESLINT 8.17.0和OpenUI5 1.102.1。
What version of the UI5 types and ESLint are you using? When I am writing the same code in my
BaseController
then I see another issue:@typescript-eslint/no-unnecessary-type-assertion
which will be auto-fixed to:
Due to the type inference there should be no casting necessary.
BTW: In my case I am using ESLint 8.17.0 and OpenUI5 1.102.1.
由于
getRouterfor()
方法已经具有声明的类型,因此该类型将通过Typescript推断。您能尝试做这样的事情:
Since the
getRouterFor()
method already has a declared type, the type will get inferred by typescript.Can you try doing something like this:
事实证明,覆盖错误来自VSCODE ESLINT扩展。
由于我们将在文件夹上用于CAP项目,该项目包含使用Typescript的CDS开发文件夹,也包含App Resources的文件夹,因此扩展名感到困惑。
有两个.eslintrc.json文件。一个在根级别(用root:true标记),一个用于Typescript UI5应用程序。
我设置了这样的扩展名的工作目录设置
,现在它有效。
谢谢@Peter Muessig的输入。
It turn out, that the linting errors came from the VSCode ESlint Extension.
Since we are using on folder for the CAP project that contains the folders for the CDS development with typescript and also a folder for the app resources, the extension got confused.
There are two .eslintrc.json files. One on the root level(marked with root:true) and one for the typescript UI5 app.
I set the working directories settings of the extension like this
and now it works.
Thank you @Peter Muessig for your input.