loaders.gl icon indicating copy to clipboard operation
loaders.gl copied to clipboard

WIP Typing scratch work

Open kylebarron opened this issue 3 years ago • 0 comments

Putting up this PR for discussion. I was playing around a bit with adding optional parameterization for types such as LoaderWithParser. I was able to get the top-level parse export to correctly return the generic ReturnType of the parse function on the loader object. I wasn't able, however, to have it see parse's overloads. Those overloads work to correctly discriminate the return object based on the shape of the loader if you call the parse function directly (i.e. FlatGeobufLoader.parse()) but not yet through the top-level parse.

const test = await parse(new ArrayBuffer(0), FlatGeobufLoader);
test
// TS can at least infer ReturnTypes here

const test2 = await parse(new ArrayBuffer(0), FlatGeobufLoader, {flatgeobuf: {shape: 'binary'}});
test2
// But doesn't infer BinaryFeatures here :/

I might come back to this at some point in the future. Could be worth a little more thought before 4.0.

kylebarron avatar Mar 14 '22 21:03 kylebarron