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

258
Vistas
Typescript error 2345 seems to be inconsistent across simple examples

I have a question about the basics of Typescript.

Consider this example:

// Interface 1
interface Empty {}

// Interface 2
interface Single {
    a: number;
}

function printEmpty(arg: Empty): void {
    console.log(`Hello World.`);
}

function printSingle(arg: Single): void {
    console.log(`Hello World, a: ${arg.a} `)
}

const obj = {a: 1, b: 2};

// ===================== Tests =====================

// TEST 1
printEmpty({a: 1, b: 2});  // valid

// TEST 2
// Q1: if the above is valid, why is this invalid
printSingle({a: 1, b: 2}) // invalid!

// TEST 3
// Q2: if the above is invalid, why is this valid
printSingle(obj);  // valid

The error I get is

Argument of type '{ a: number; b: number; }' is not assignable to parameter of type 'Single'. Object literal may only specify known properties, and 'b' does not exist in type 'Single'.(2345)

Why does TEST 2 fail but TEST 1 and TEST 3 pass?

Here's a reproduction of this error on the official TS playground: [LINK]

about 4 years ago · Juan Pablo Isaza
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