Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
UIComponent.getRouterFor shows TypeScript error: Unsafe return of an 'any' typed value

I recently added TypeScript to my SAPUI5 project and having problems with the ESLint messages for the types.

Considers this easy example: enter image description here

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: enter image description here

Can someone tell me what I am doing wrong? Are the types correct?

about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

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

public getRouter(this: BaseController) {
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
    return UIComponent.getRouterFor(this) as Router;
}

which will be auto-fixed to:

public getRouter(this: BaseController) {
    return UIComponent.getRouterFor(this);
}

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.

about 4 years ago · Santiago Gelvez Relatório

0

Since the getRouterFor() method already has a declared type, the type will get inferred by typescript. Can you try doing something like this:

public getRouter(this: BaseController) : Router {
 return UIComponent.getRouterFor(this) 
}
about 4 years ago · Santiago Gelvez Relatório

0

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

"eslint.workingDirectories": ["./app", "./srv", "./db"],

and now it works.

Thank you @Peter Muessig for your input.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda