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

592
Vistas
'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation

The first snippet is the code im working with and below is the error it throws and it happens on every "yield select" portion that is in the code and im not sure what my next step is.

function* onLoadingDomainsresult() {
  const pathname = yield select(getPathname);

  interface Params {
    hastag: string;
  }

'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.  TS7057

    113 | 
    114 | function* onLoadingDomainsresult() {
  > 115 |   const pathname = yield select(getPathname);
        |                    ^
    116 | 
    117 |   interface Params {
    118 |     hastag: string;
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

The literal type of select(getPathname) doesn't relate to the value you get back from the yield. select(getPathname) is the value yielded by your co-routine to its iterating context.

The value injected into your generator by its running context (through the next() call) DOES matter to the type you get back from the yield expression.

Either way, currently Typescript has no metadata about what it's going to get at all, since your generator function has no type annotation.

I'm guessing this is redux-saga.

A typical Generator function type annotation is something like...

type WhatYouYield="foo"
type WhatYouReturn="bar"
type WhatYouAccept="baz"

function* myfun(): Generator<
  WhatYouYield,
  WhatYouReturn,
  WhatYouAccept
> {
const myYield = "foo" //type of myYield is WhatYouYield
const myAccepted = yield myYield; //type of myAccepted is WhatYouAccept
return "baz" //type of this value is WhatYouReturn 
}

...and the error you're getting is from Typescript having to guess the WhatYouAccept type without the Generator type annotation on your function.

over 4 years ago · Santiago Trujillo Denunciar

0

I got same error and I solved it.

export interface ResponseGenerator{
    config?:any,
    data?:any,
    headers?:any,
    request?:any,
    status?:number,
    statusText?:string
}
const response:ResponseGenerator = yield YOUR_YIELD_FUNCTION
console.log(response.data)

over 4 years ago · Santiago Trujillo Denunciar

0

In recent updates of typescript, there are more type restrictions on generator functions.

Type 1: yield with call

function* initDashboard(): any {
  let response = yield call(getDashboardData);
  console.log(response);
}

Type 2: yield without call

function* initDashboard() {
  let response: any = yield getDashboardData;
  console.log(response);
}

Note: Using any is fastest solution but proper solution would be creating type/interface for the response and using it as type.

over 4 years ago · Santiago Trujillo 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