0

I am quite new to typescript and i am wondering if (probably is) its possible to extend a type coming from an installed library?

for example i have added a library wich exports this type:

export declare type RequestParams2_0_0 = {
    version: '2.0.0';
    typeNames: string;
    count?: number;
};

but I need it to be like this:

export declare type RequestParams2_0_0 = {
    version: '2.0.0';
    typeNames: string;
    count?: number;
    bbox?: [number, number, number, number]
};

it would not make sense (or would it?) to just change it in the library (in this case WfsDataParser.d.ts). i would like to extend this somehow in my code that it accepts bbox without changing the library.

currently i import the Type like so:

import { WfsDataParser, RequestParams, RequestBaseParams } from 'geostyler-wfs-parser'

and this is how RequestParams looks in the WfsDataParser.d.ts

export declare type RequestParams = GetFeatureOptionalParams & (RequestParams1_1_0 | RequestParams2_0_0);

but RequestParams needs to accept another paramerter... how would i do that?

Thank you so much!

Hannes F
  • 339
  • 2
  • 11
  • 2
    *"but I need it to be like this"* Why? Any actual runtime object you got from the library would not have a `bbox` property (or at least, not a documented one it would be safe to use). Why not create your own type for use where you know you may have `bbox`? – T.J. Crowder Nov 01 '22 at 08:20
  • 2
    E.g., `type MyRequestParams = RequestParams2_0_0 & { bbox?: [number, number, number, number]; };` – T.J. Crowder Nov 01 '22 at 08:29
  • 1
    genius! thanks a log - that solves it! – Hannes F Nov 01 '22 at 08:50

0 Answers0