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

328
Vistas
No constituent of type 'true | CallableFunction' is callable

The full error:

This expression is not callable.
  No constituent of type 'true | CallableFunction' is callable

This is the code that was triggering the error:

public static base(
    text,
    callB: boolean | CallableFunction = false,
    
  ) {
    const sw = Swal.fire({
      text,
      });

    if (callB) {
      sw.then(callB());
    }
  }

I changed the type of callB to :

 callB: (param: any) => void |boolean = false

and when I remove the callB type definition:

callB= false

I get this error:

This expression is not callable.
  Type 'Boolean' has no call signatures
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This is what you are looking for:

function base(text: string, callB: false | CallableFunction = false) {
  console.log(text);
  if (callB) {
    callB();
  }
}

Essentially, you want to pass a function or false. When it is truthy you want to call the function.

But as per your definition

function base(text: string, callB: boolean | CallableFunction = false) {
  console.log(text);
  if (callB) {
    callB();
  }
}

this would be a valid call base('some str', true) where callB is true and not a function that it will try to execute using callB(). Not boolean is not callable, it is? Hence the error.

TS Playground link: https://tsplay.dev/m056qW

about 4 years ago · Juan Pablo Isaza Denunciar

0

The type

boolean | Function

is equivalent to

true | false | Function

Now because a value of type Function is truthy, your check

if (callB)

narrows the type of callB to

true | Function

and true is not callable, hence the error.

It's not clear how your base method is meant to be used so I've outlined two solutions:

If true isn't a valid input, adjust your parameter type accordingly

static base(
    text, 
    callB: false | CallableFunction = false
) {
    if (callB) {
        callB();
    }
}

If true is a case you must handle, use a more precise conditional check such as

if (typeof callB === 'function') {
    callB() // OK
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you use false | Callablefunction (or boolean | CallableFunction) , you can coerce type by using typeof:

static base(
    text,
    callB: false | CallableFunction = false
) {
    if (typeof callB === "function") {
        callB()
    }
}
about 4 years ago · Juan Pablo Isaza 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