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

320
Views
Confusing compiler error: Argument of type 'string' is not assignable to parameter of type

I have an array with acceptable mime types:

export const frontend = { 
  ...
  zipMimeTypes: [
    "application/zip",
    "application/x-zip-compressed",
    "multipart/x-zip",
  ],
} as const;

I want to include it in another file and use it like so:

frontend.zipMimeTypes.includes(file.type)

However, my TS compiler is complaining about file.type

Argument of type 'string' is not assignable to parameter of type '"application/zip" | "application/x-zip-compressed" | "multipart/x-zip"'.

I just do:

  [
    "application/zip",
    "application/x-zip-compressed",
    "multipart/x-zip",
  ].includes(file.type)

It works

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The issue is in as const. Instead, you can define an interface to use with frontend:

interface Frontend {
  zipMimeTypes: string[];
}
const frontend: Frontend = {
  zipMimeTypes: [
    "application/zip",
    "application/x-zip-compressed",
    "multipart/x-zip"
  ]
};
about 4 years ago · Juan Pablo Isaza Report

0

Although forcing zipMimeTypes to be a string array will get rid of the error, you have now lost your typing for zipMimeTypes.

Instead I would create a type for your zipMimeTypes.

The advantages is that code-completion works nicely too.

export const frontend = { 
  zipMimeTypes: [
    "application/zip",
    "application/x-zip-compressed",
    "multipart/x-zip",
  ],
} as const;

type zipMimeType = typeof frontend.zipMimeTypes[number];

interface File {
    type: zipMimeType;
}

const file:File = {
    type: 'application/zip'
}

if (frontend.zipMimeTypes.includes(file.type)) {
  //etc.
}

TS Playground

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