Case Sensitive attribute

Asked

Viewed 32 times

-1

Good afternoon, everyone!

I have a class called Inventory that has the following attributes:

import InventoryItem from "./InventoryItem";
import InventoryConfiguration from "./InventoryConfiguration";

export default class Inventory {
  id: string;

  inventoryStatus: InventoryStatus;

  inventoryConfiguration: InventoryConfiguration;

  creationDate: Date;

  inventoryItems: InventoryItem[];

  inventoryReadedItems: InventoryItem[];
}

And in my API service, I get a get like this:

  async getInventory(id: string): Promise<Inventory> {
    this.store.select(a => a.user.token).subscribe(a => (this.userToken = a));

    return this.http
      .get<Inventory>(this.baseUrl + `/Inventories/${id}`, {
        headers: {
          Authorization: `Bearer ${this.userToken.access_token}`
        }
      })
      .toPromise();
  }

However, when using the service to check if returned a value in the Id, my method getInventory that should return exactly the same as the class, because I typed.

But it’s back in the field id as Id (I capital).. So, when I go to do the if below, it falls into LSE because of this, they can help me to solve this problem?

inserir a descrição da imagem aqui

1 answer

0

Hello, although Typescript type your data it will come exactly as it comes from the backend. There is a difference between typing and casting. If you speak pro typescript that your back will send you bananas and in practice send you apples it will not know how to convert from one to the other and will send you apples.

In this case either you do the interface exactly as it comes from the back or do a map of the state of the application’s pro state.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.