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

127
Views
Mapping JSON object into Typed object with enum property

I am wanting to convert a JSON "string" that I pull from an api into my Typescript model, if i change one of the props from enum to string it works quite easily, however I cannot seem to map it to an enum despite hours of searching and trying different things.

I have a model that holds an array of types like this

export enum SEAT_TYPE {
  ECONOMY = "ECONOMY",
  PREMIUM_ECONOMY = "PREMIUM_ECONOMY",
  BUSINESS = "BUSINESS",
}

export type Seat = {
  number: string;
  type: SEAT_TYPE;
  status: boolean;
};

export class SeatingPlan {
  seating: Seat[] = [];
}

I then pull something like this from an api

  [{
    number: "1A",
    type: "BUSINESS",
    status: false,
  },
  {
    number: "1B",
    type: "BUSINESS",
    status: false,
  },
  {
    number: "1C",
    type: "BUSINESS",
    status: false,
  }]

An i'm using just a basic loop function to map over each element and convert it to a typed object like this

export function convert(json: Array<Seat>) {
  return json.map(
    (seat) =>
      <Seat>{
        number: seat.number,
        type: seat.type as keyof typeof SEAT_TYPE,
        status: seat.status,
      },
  );
}

But where i call my

convert(JSON)

I get this error and I'm totally lost at this point, i'm semi-new to typescript and i feel like i'm missing something quite simple, any help would be greatly appreciated.

Argument of type '{ number: string; type: string; status: boolean; }[]' is not assignable to parameter of type 'Seat[]'.
  Type '{ number: string; type: string; status: boolean; }' is not assignable to type 'Seat'.
    Types of property 'type' are incompatible.
      Type 'string' is not assignable to type 'SEAT_TYPE'.

Thanks in advance.

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!