Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

398
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda