class-transformer
class-transformer copied to clipboard
Cannot Use plainToClass with GeoLocationPosition
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.