class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

Cannot Use plainToClass with GeoLocationPosition

Open tuckerjt07 opened this issue 3 years ago • 0 comments

There is a bug with trying to use a property of type GeoLocationPosition with plainToClass. The code falls into Line 144 TransformOperationExecutor.js else if (targetType) { newValue = new targetType(); }. The issue with this is that calling a constructor on GeoLocationPosition results in an "illegal constructor" error. I got around this by creating a singleton instance of the class

export class CustomGeoLocationPosition {
  private static instance: CustomGeoLocationPosition;
  public coords!: GeolocationCoordinates;
  public timestamp!: number;

  // eslint-disable-next-line @typescript-eslint/no-empty-function
  private constructor() {}

  static getInstance() {
    if (!this.instance) {
      this.instance = new CustomGeoLocationPosition();
    }

    return this.instance;
  }
}

and using that to pass the values around with but it would be nice if there was a way to indicate that a new instance of the original class should not be instantiated.

tuckerjt07 avatar Feb 06 '22 21:02 tuckerjt07