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

231
Views
Why doesn't my TypeScript interface alert me that it is missing some properties?

I have a TypeScript interface with required properties.

But when typing an object and pushing it into an array there is no error message alerting me that some of the required properties are missing.

Here is an example from my code:

interface Keyword {
  keyword: string;
  language: string;
  location: string;
  searchEngineDomain: string;
  organicPositionLastThirtyDays: number[];
  createdAt: string;
}

const keywords = [];
keywords.push({
    keyword: 'My First Keyword',
} as Keyword);

I was expecting to see an error telling me the object I am pushing into the array is missing five required properties. But I see no error at all.

Why does this happen?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's because keywords is of type any[], while it should be Keyword[]. You should also remove as Keyword as it kinda means "believe me, it's all we want here". Type assertions can hide type errors.

Check out the following snippet:

interface Keyword {
  keyword: string;
  language: string;
  location: string;
  searchEngineDomain: string;
  organicPositionLastThirtyDays: number[];
  createdAt: string;
}

const keywords: Keyword[] = [];
keywords.push({
    keyword: 'My First Keyword',
});

You will receive the following error:

Argument of type '{ keyword: string; }' is not assignable to parameter of type 'Keyword'. Type '{ keyword: string; }' is missing the following properties from type 'Keyword': language, location, searchEngineDomain, organicPositionLastThirtyDays, createdAt

about 4 years ago · Santiago Trujillo Report
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!