#Union type getAll method for service

7 messages · Page 1 of 1 (latest)

fading sky
#

Hi, i'm trying to implement a getall method for abstract object of "AbstractGeometry" but getting a error message of "Type '(Promise<AreaGeometry[]> | Promise<LineGeometry[]> | Promise<PointGeometry[]>)[]' is missing the following properties from type 'Promise<AbstractGeometry[][]>': then, catch, finally, [Symbol.toStringTag]ts(2739)"

here is the code:

//Type '(Promise<AreaGeometry[]> | Promise<LineGeometry[]> | Promise<PointGeometry[]>)[]' is missing the following properties from type 'Promise<AbstractGeometry[][]>': then, catch, finally, [Symbol.toStringTag]ts(2739) 

  getAll(): Promise<(AbstractGeometry|null)[][] | null> {
    let areas = this.areaService.getAll();
    let lines = this.lineService.getAll();
    let points = this.pointService.getAll();
    if (!areas && !lines && !points) throw new Error("there isn't any geometry objects");
    return [areas, lines, points]; 
  }

here is the other objects:

export type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon | GeometryCollection;
export interface AbstractGeometry {
    id: number;
    geom: Geometry;
} 
@Entity('areaGeometry')
export class AreaGeometry extends GenericEntity implements AbstractGeometry {
    
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        type: 'geometry',
        spatialFeatureType: 'Polygon',
        srid: 4326, // WGS84 reference system
        transformer: new GeometryTransformer(),
        nullable: false
    })
    geom: Polygon; // import from 'wkx'
#

@Entity('lineGeometry')
export class LineGeometry extends GenericEntity implements AbstractGeometry {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        type: 'geometry',
        spatialFeatureType: 'LineString',
        srid: 4326, // WGS84 reference system
        transformer: new GeometryTransformer(),
        nullable: false
    })
    geom: LineString;
}



@Entity('pointGeometry')
export class PointGeometry extends GenericEntity implements AbstractGeometry {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        type: 'geometry',
        spatialFeatureType: 'Point',
        srid: 4326, // WGS84 reference system
        transformer: new GeometryTransformer(),
        nullable: false
    })
    geom: Point;
}
chrome yew
#

I believe you missed an await on those .getAll() calls

fading sky
#

not its a call of this.repository.find()

chrome yew
#

then, yes, you missed the await

fading sky
#

ok thanks that probably it