danmarshall/deckgl-typings

Please provide a sample for "Implement a layer from scratch"

JannikGM opened this issue · 0 comments

This simple bit of code from the deck.gl docs won't work when copied naively:

  • "Error: TS2707: Generic type 'Layer<D, P>' requires between 1 and 2 type arguments." leads to:
    • this.context not found
    • this.setState not found
    • this.props not found

Looking at the existing typings, it looks like I need something convoluted like:

export interface CubeLayerProps<D> extends LayerProps<D> {
  image: any;
}
export default class CubeLayer<D, P extends CubeLayerProps<D> = CubeLayerProps<D>> extends Layer<D, P> {

However, then I still get problems with another sample for defining custom uniforms, because what I pass into super.draw({uniforms: [...]} is incomplete; it requires the optional fields (parameters, context, moduleParameters) to be set.

I'm not sure if these are bugs in the typings or wether these are expected changes (while I expect some change to add types, this convoluted style to define the new layer looks like bad design).
Figuring this out on my own took longer than it should have taken.
There should be a sample to guide users in the right direction, and to assure them that they are using the deck.gl as intended in their TypeScript projects.