Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!