0

Using the guid-typescript package, I wanted to use Guid types in my response model to be more descriptive.

import {Guid} from 'guid-typescript';

export class Product {
    id: Guid;
    name: string;
}

...
this.http.get<Product[]>(...);

In runtime, however, product.id is a string type, not a Guid type. How can I inform the angular http library on how to handle these types?

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95

1 Answers1

0

As you might see in the definition of the Guid class, internally it's a string. Also Javascript doesn't support Guid data types, it's always a string.

If you are retrieving a Guid from your backend take into account that the library just offers a class called Guid and that the Guid datatype is serialized to string from your backend.

HNL
  • 103
  • 13
  • Internally it's stored within the class as a string, but it should still be serialized to a Guid object. Javascript does support Guid data types, that's exactly what the guid class is doing, creating a data type for it. – Devon Bessemer Oct 04 '19 at 19:24