diff --git a/README.md b/README.md index 75681ec..d7a7442 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ TypeScript declaration files for [deck.gl](https://deck.gl/#/documentation/) This is a work in progress - see the [issues list](https://github.com/danmarshall/deckgl-typings/issues) -``` +```bash npm install @danmarshall/deckgl-typings ``` @@ -14,28 +14,58 @@ Then it is possible to link the mappings in your project so typescript can find Create a new file like `deckgl.d.ts` (although it could be named anything ending in `.d.ts`) in your `src/` directory with the following code: -``` -import * as DeckTypings from "@danmarshall/deckgl-typings" -declare module "deck.gl" { - export namespace DeckTypings {} +```typescript +import * as DeckTypings from '@danmarshall/deckgl-typings'; +declare module 'deck.gl' { + export namespace DeckTypings {} } ``` ## Version mapping -| deck.gl version | deckgl-typings version | -| --------------- | ---------------------- | -| 5.x.x | 1.x.x | -| 6.x.x | 2.x.x | -| 7.x.x | 3.x.x | -| 8.x.x | 4.x.x | +| deck.gl version | deckgl-typings version | type inference | +| --------------- | ---------------------- | -------------- | +| 5.x.x | 1.x.x | N | +| 6.x.x | 2.x.x | N | +| 7.x.x | 3.x.x | N | +| 8.x.x | 4.x.x | N | +| 8.x.x | 5.x.x | Y | + +## Upgrading to v5 + +### Automatic typing on data accessors + +For data types `Array`, `Iterable`, `AsyncIterable`, and `Promise`, accessors can now infer the type of the datum they operate on: + +```typescript +new TextLayer({ + data: [1], + getPosition(x) { + // <-- x is of type number because data is type number[] + return [x, 0]; + }, +}); +``` + +For most use cases, simply removing the explicit types from the Layer constructors will allow type inference to determine the correct type of data and of data accessors. + +### Non-iterable data + +Typing now supports using data buffers directly: + +```typescript +new TextLayer({ + data: { + attributes: { getPosition: new Int8Array([1, 2, 3, 4]) }, + length: 4, + }, +}); +``` ## Known issues -These typings are now v4 which targets deck.gl v8. The following issues are changes to v8 from deck.gl v7 which have not been added to these typings: +These typings are now v5 which targets deck.gl v8. The following issues are changes to v8 from deck.gl v7 which have not been added to these typings: -- [ ] [It is now possible to replace a layer's accessors with binary data attributes.](https://github.com/uber/deck.gl/blob/master/docs/whats-new.md#better-binary-data-support) -- [ ] [GPU filtering for layers](https://github.com/uber/deck.gl/blob/master/docs/whats-new.md#gpu-data-filter-in-aggregation-layers) - Adds a [getFilterValue](https://github.com/uber/deck.gl/blob/master/docs/api-reference/extensions/data-filter-extension.md#getfiltervalue-function) to some layers. - [ ] [Optional specifying the \_framebuffer prop of Deck.](https://github.com/uber/deck.gl/blob/master/docs/whats-new.md#other-new-features-and-improvements) - [ ] [Pick a 3d surface point in the scene](https://github.com/uber/deck.gl/blob/master/docs/whats-new.md#other-new-features-and-improvements) by passing unproject3D: true to deck.pickObject or deck.pickMultipleObjects. - [ ] ArcLayer supports drawing arcs between two 3D positions diff --git a/deck.gl__aggregation-layers/index.d.ts b/deck.gl__aggregation-layers/index.d.ts index 896bfae..1d01859 100644 --- a/deck.gl__aggregation-layers/index.d.ts +++ b/deck.gl__aggregation-layers/index.d.ts @@ -5,12 +5,29 @@ declare module '@deck.gl/aggregation-layers/utils/prop-utils' { declare module '@deck.gl/aggregation-layers/aggregation-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; - export interface AggregationLayerProps extends CompositeLayerProps {} + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; + import { DataFilterExtension, ExtensionProps } from '@deck.gl/extensions'; + + export type AggregationLayerProps = Array> = CompositeLayerProps & + ExtensionProps< + E, + DataFilterExtension, + { + filterRange: [number, number]; + filterSoftRange?: [number, number]; + filterTransformColor?: boolean; + filterTransformSize?: boolean; + getFilterValue: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number | number[]; + onFilteredItemsChange?: (event: { id: string; count: number }) => void; + } + >; + export default class AggregationLayer< - D, - P extends AggregationLayerProps = AggregationLayerProps - > extends CompositeLayer { - constructor(props: AggregationLayerProps); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(dimensions: any): void; updateAttributes(changedAttributes: any): void; getAttributes(): any; @@ -282,13 +299,20 @@ declare module '@deck.gl/aggregation-layers/cpu-grid-layer/grid-aggregator' { }; } declare module '@deck.gl/aggregation-layers/grid-aggregation-layer' { + import { LayerData } from '@deck.gl/core/lib/layer'; import AggregationLayer, { AggregationLayerProps } from '@deck.gl/aggregation-layers/aggregation-layer'; - export interface GridAggregationLayerProps extends AggregationLayerProps {} - export default class GridAggregationLayer< + + export type GridAggregationLayerProps = Array> = AggregationLayerProps< D, - P extends GridAggregationLayerProps = GridAggregationLayerProps - > extends AggregationLayer { - constructor(props: GridAggregationLayerProps); + E + >; + + export default class GridAggregationLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends AggregationLayer & P, S, E> { initializeState({ dimensions }: { dimensions: any }): void; finalizeState(): void; updateShaders(shaders: any): void; @@ -324,12 +348,16 @@ declare module '@deck.gl/aggregation-layers/screen-grid-layer/screen-grid-layer- } declare module '@deck.gl/aggregation-layers/screen-grid-layer/screen-grid-cell-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; - export interface ScreenGridCellLayerProps extends LayerProps {} + import { LayerData, LayerProps } from '@deck.gl/core/lib/layer'; + + export type ScreenGridCellLayerProps = Array> = LayerProps; + export default class ScreenGridCellLayer< - D, - P extends ScreenGridCellLayerProps = ScreenGridCellLayerProps - > extends Layer { + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { static isSupported(gl: any): any; getShaders(): { vs: string; @@ -353,27 +381,30 @@ declare module '@deck.gl/aggregation-layers/screen-grid-layer/screen-grid-cell-l } declare module '@deck.gl/aggregation-layers/screen-grid-layer/screen-grid-layer' { import GridAggregationLayer from '@deck.gl/aggregation-layers/grid-aggregation-layer'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { AggregationLayerProps } from '@deck.gl/aggregation-layers/aggregation-layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorDomain, ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface ScreenGridLayerProps extends LayerProps { - //Render Options - cellSizePixels?: number; - cellMarginPixels?: number; - colorDomain?: ColorDomain; - colorRange?: ColorRange; - gpuAggregation?: boolean; - aggregation?: string; - //Data Accessors - getPosition?: (d: D) => Position; - getWeight?: (d: D) => number; - } + export type ScreenGridLayerProps = Array> = LayerProps & + AggregationLayerProps & { + //Render Options + cellSizePixels?: number; + cellMarginPixels?: number; + colorDomain?: ColorDomain; + colorRange?: ColorRange; + gpuAggregation?: boolean; + aggregation?: string; + // Data Accessors + getPosition?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => Position) | Position; + getWeight?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + }; export default class ScreenGridLayer< - D, - P extends ScreenGridLayerProps = ScreenGridLayerProps - > extends GridAggregationLayer { - constructor(props: ScreenGridLayerProps); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends GridAggregationLayer & P, S, E> { initializeState(params: any): void; renderLayers(): any; finalizeState(): void; @@ -539,10 +570,14 @@ declare module '@deck.gl/aggregation-layers/utils/cpu-aggregator' { declare module '@deck.gl/aggregation-layers/cpu-grid-layer/cpu-grid-layer' { import AggregationLayer, { AggregationLayerProps } from '@deck.gl/aggregation-layers/aggregation-layer'; import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; - import { ObjectInfo } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorDomain, ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface CPUGridLayerProps extends AggregationLayerProps { + + export type CPUGridLayerProps = Array> = AggregationLayerProps< + D, + E + > & { cellSize?: number; colorDomain?: ColorDomain; colorRange?: ColorRange; @@ -557,21 +592,23 @@ declare module '@deck.gl/aggregation-layers/cpu-grid-layer/cpu-grid-layer' { elevationLowerPercentile?: number; colorScaleType?: string; material?: Object; - getPosition?: (d: D) => Position; - getColorValue?: (d: D[], objectInfo: ObjectInfo) => number; - getColorWeight?: (d: D) => number; colorAggregation?: string; - getElevationValue?: (points: D[], objectInfo: ObjectInfo) => number; - getElevationWeight?: (d: D) => number; elevationAggregation?: AggregationOperation; onSetColorDomain?: () => void; onSetElevationDomain?: () => void; - } - export default class CPUGridLayer = CPUGridLayerProps> extends AggregationLayer< - D, - P - > { - constructor(props: CPUGridLayerProps); + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColorValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getColorWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + getElevationValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getElevationWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; + export default class CPUGridLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends AggregationLayer & P, S, E> { initializeState(params: any): void; _onGetSublayerColor(cell: any): any; _onGetSublayerElevation(cell: any): any; @@ -613,10 +650,14 @@ declare module '@deck.gl/aggregation-layers/hexagon-layer/hexagon-aggregator' { declare module '@deck.gl/aggregation-layers/hexagon-layer/hexagon-layer' { import AggregationLayer, { AggregationLayerProps } from '@deck.gl/aggregation-layers/aggregation-layer'; import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; - import { ObjectInfo } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorDomain, ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface HexagonLayerProps extends AggregationLayerProps { + + export type HexagonLayerProps = Array> = AggregationLayerProps< + D, + E + > & { //Render Options radius?: number; hexagonAggregator?: Function; @@ -633,23 +674,23 @@ declare module '@deck.gl/aggregation-layers/hexagon-layer/hexagon-layer' { elevationUpperPercentile?: number; elevationLowerPercentile?: number; material?: Object; - - //Data Accessors - getPosition?: (d: D) => Position; - getColorValue?: (d: D[], objectInfo: ObjectInfo) => any; - getColorWeight?: (d: D) => any; colorAggregation?: string; - getElevationValue?: (d: D[], objectInfo: ObjectInfo) => any; - getElevationWeight?: (d: D) => any; elevationAggregation?: AggregationOperation; onSetColorDomain?: Function; onSetElevationDomain?: Function; - } - export default class HexagonLayer = HexagonLayerProps> extends AggregationLayer< - D, - P - > { - constructor(props: HexagonLayerProps); + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColorValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getColorWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + getElevationValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getElevationWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; + export default class HexagonLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends AggregationLayer & P, S, E> { initializeState(params: any): void; updateRadiusAngle(vertices: any): void; convertLatLngToMeterOffset(hexagonVertices: any): number[][]; @@ -728,24 +769,29 @@ declare module '@deck.gl/aggregation-layers/contour-layer/contour-utils' { declare module '@deck.gl/aggregation-layers/contour-layer/contour-layer' { import GridAggregationLayer, { GridAggregationLayerProps } from '@deck.gl/aggregation-layers/grid-aggregation-layer'; import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; - export interface ContourLayerProps extends GridAggregationLayerProps { + + export type ContourLayerProps = Array> = GridAggregationLayerProps< + D, + E + > & { //Render Options cellSize?: number; gpuAggregation?: boolean; aggregation?: AggregationOperation; contours?: Array; zOffset?: number; - - //Data Accessors - getPosition?: (d: D) => Position; - getWeight?: (d: D) => number; - } + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; export default class ContourLayer< - D, - P extends ContourLayerProps = ContourLayerProps - > extends GridAggregationLayer { - constructor(props: ContourLayerProps); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends GridAggregationLayer & P, S, E> { initializeState(params: any): void; renderLayers(): any[]; updateAggregationState(opts: any): void; @@ -765,11 +811,12 @@ declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer-f } declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; import { ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface GPUGridCellLayerProps extends LayerProps { + + export type GPUGridCellLayerProps = Array> = LayerProps & { //Render Options cellSize?: number; colorRange?: ColorRange; @@ -779,18 +826,19 @@ declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer' elevationScale?: number; extruded?: boolean; material?: any; - - //Data Accessors - getPosition?: (d: D) => Position; - getColorWeight?: (d: D) => number; colorAggregation?: string; - getElevationWeight?: (d: D) => number; elevationAggregation?: AggregationOperation; - } - export default class GPUGridCellLayer = GPUGridCellLayerProps> extends Layer< - D, - P - > { + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColorWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + getElevationWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; + export default class GPUGridCellLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; _getModel(gl: any): any; @@ -804,9 +852,14 @@ declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer' declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-layer' { import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; import GridAggregationLayer, { GridAggregationLayerProps } from '@deck.gl/aggregation-layers/grid-aggregation-layer'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface GPUGridLayerProps extends GridAggregationLayerProps { + + export type GPUGridLayerProps = Array> = GridAggregationLayerProps< + D, + E + > & { //Render Options cellSize?: number; colorRange?: ColorRange; @@ -816,19 +869,19 @@ declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-layer' { elevationScale?: number; extruded?: boolean; material?: any; - - //Data Accessors - getPosition?: (d: D) => Position; - getColorWeight?: (d: D) => number; colorAggregation?: string; - getElevationWeight?: (d: D) => number; elevationAggregation?: AggregationOperation; - } + // Data Acessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColorWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + getElevationWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; export default class GPUGridLayer< - D, - P extends GPUGridLayerProps = GPUGridLayerProps - > extends GridAggregationLayer { - constructor(props: GPUGridLayerProps); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends GridAggregationLayer & P, S, E> { initializeState(params: any): void; getHashKeyForIndex(index: any): string; getPositionForIndex(index: any): any[]; @@ -841,11 +894,12 @@ declare module '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-layer' { declare module '@deck.gl/aggregation-layers/grid-layer/grid-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; - import { ObjectInfo } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorDomain, ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; import { AggregationOperation } from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; - export interface GridLayerProps extends CompositeLayerProps { + + export type GridLayerProps = Array> = CompositeLayerProps & { //Render Options cellSize?: number; colorDomain?: ColorDomain; @@ -863,20 +917,23 @@ declare module '@deck.gl/aggregation-layers/grid-layer/grid-layer' { fp64?: boolean; gpuAggregation?: boolean; material?: any; - - //Data Accessors - getPosition?: (d: D) => Position; - getColorValue?: (points: D[], objectInfo: ObjectInfo) => number; - getColorWeight?: (d: D) => number; colorAggregation?: string; - getElevationValue?: (points: D[], objectInfo: ObjectInfo) => number; - getElevationWeight?: (d: D) => number; elevationAggregation?: AggregationOperation; onSetColorDomain?: () => void; onSetElevationDomain?: () => void; - } - export default class GridLayer = GridLayerProps> extends CompositeLayer { - constructor(props: GridLayerProps); + // Data Acessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColorValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getColorWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + getElevationValue?: (objects: LayerDataAccessor[], objectInfo: ObjectInfo) => number; + getElevationWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; + export default class GridLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(params: any): void; renderLayers(): any; canUseGPUAggregation(props: any): boolean; @@ -903,7 +960,13 @@ declare module '@deck.gl/aggregation-layers/heatmap-layer/triangle-layer-fragmen } declare module '@deck.gl/aggregation-layers/heatmap-layer/triangle-layer' { import { Layer } from '@deck.gl/core'; - export default class TriangleLayer extends Layer { + import { LayerData, LayerProps } from '@deck.gl/core/lib/layer'; + export default class TriangleLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): { vs: string; fs: string; @@ -928,9 +991,14 @@ declare module '@deck.gl/aggregation-layers/heatmap-layer/max-vs.glsl' { } declare module '@deck.gl/aggregation-layers/heatmap-layer/heatmap-layer' { import AggregationLayer, { AggregationLayerProps } from '@deck.gl/aggregation-layers/aggregation-layer'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ColorDomain, ColorRange } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface HeatmapLayerProps extends AggregationLayerProps { + + export type HeatmapLayerProps = Array> = AggregationLayerProps< + D, + E + > & { //Render Options radiusPixels?: number; colorRange?: ColorRange; @@ -938,16 +1006,16 @@ declare module '@deck.gl/aggregation-layers/heatmap-layer/heatmap-layer' { threshold?: number; colorDomain?: ColorDomain; aggregation?: 'SUM' | 'MEAN'; - - //Data Accessors - getPosition?: (d: D) => Position; - getWeight?: (d: D) => number; - } - export default class HeatmapLayer = HeatmapLayerProps> extends AggregationLayer< - D, - P - > { - constructor(props: HeatmapLayerProps); + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getWeight?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => number; + }; + export default class HeatmapLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends AggregationLayer & P, S, E> { initializeState(params: any): void; renderLayers(): any; finalizeState(): void; diff --git a/deck.gl__carto/index.d.ts b/deck.gl__carto/index.d.ts index 76c5177..1fdcbc2 100644 --- a/deck.gl__carto/index.d.ts +++ b/deck.gl__carto/index.d.ts @@ -17,7 +17,14 @@ declare module '@deck.gl/carto/basemap' { } declare module '@deck.gl/carto/layers/carto-layer' { import { CompositeLayer } from '@deck.gl/core'; - export default class CartoLayer extends CompositeLayer { + import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; + import { LayerData } from '@deck.gl/core/lib/layer'; + export default class CartoLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(): void; updateState({ changeFlags }: { changeFlags: any }): void; _updateTileJSON(): Promise; @@ -33,13 +40,27 @@ declare module '@deck.gl/carto/api/maps-api-client' { } declare module '@deck.gl/carto/layers/carto-sql-layer' { import CartoLayer from '@deck.gl/carto/layers/carto-layer'; - export default class CartoSQLLayer extends CartoLayer { + import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; + import { LayerData } from '@deck.gl/core/lib/layer'; + export default class CartoSQLLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CartoLayer & P, S, E> { _updateTileJSON(): Promise; } } declare module '@deck.gl/carto/layers/carto-bqtiler-layer' { import CartoLayer from '@deck.gl/carto/layers/carto-layer'; - export default class CartoBQTilerLayer extends CartoLayer { + import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; + import { LayerData } from '@deck.gl/core/lib/layer'; + export default class CartoBQTilerLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CartoLayer & P, S, E> { _updateTileJSON(): Promise; } } diff --git a/deck.gl__core/index.d.ts b/deck.gl__core/index.d.ts index c32264a..0524de4 100644 --- a/deck.gl__core/index.d.ts +++ b/deck.gl__core/index.d.ts @@ -923,7 +923,7 @@ declare module '@deck.gl/core/lifecycle/component-state' { } declare module '@deck.gl/core/lifecycle/component' { import { LayerContext } from '@deck.gl/core/lib/layer'; - export default class Component

{ + export default class Component { constructor(props: P, ...additionalProps: P[]); clone(newProps: P): any; get stats(): any; @@ -959,7 +959,7 @@ declare module '@deck.gl/core/lifecycle/component' { /** * Will be set to the shared layer state object during layer matching */ - state: any; + state: S; internalState: any; } @@ -973,6 +973,7 @@ declare module '@deck.gl/core/lib/layer-state' { } } declare module '@deck.gl/core/lib/layer' { + import { TypedArray } from '@deck.gl/core'; import AttributeManager from '@deck.gl/core/lib/attribute/attribute-manager'; import Component from '@deck.gl/core/lifecycle/component'; import Deck, { PickInfo, PickMode } from '@deck.gl/core/lib/deck'; @@ -981,8 +982,73 @@ declare module '@deck.gl/core/lib/layer' { import LayerManager from '@deck.gl/core/lib/layer-manager'; import Viewport from '@deck.gl/core/viewports/viewport'; import { Position } from '@deck.gl/core/utils/positions'; + import { BrushingExtension, ExtensionProps } from '@deck.gl/extensions'; import { Matrix4 } from '@math.gl/core'; import { UNIT } from '@deck.gl/core/lib/constants'; + import { Buffer as LumaBuffer } from '@luma.gl/core'; + + export interface DataAttribute { + buffer?: LumaBuffer; + normalized?: boolean; + offset?: number; + size?: number; + stride?: number; + type?: number; + value?: TypedArray; + [k: string]: any; + } + + type NonIterableData = { + attributes: { + [K in T]?: LumaBuffer | TypedArray | DataAttribute; + }; + length: number; + [k: string]: any; + }; + + type Mutable = { -readonly [K in keyof T]: Mutable }; + + export type LayerData = + | string + | NonIterableData> + | AsyncIterable + | Promise + | Iterable + | Array; + + type _LayerDataAccessor = D extends string + ? unknown + : D extends NonIterableData + ? unknown + : D extends AsyncIterable + ? Mutable + : D extends Iterable + ? Mutable + : D extends Array + ? Mutable + : never; + + export type LayerDataAccessor = D extends Promise ? _LayerDataAccessor : _LayerDataAccessor; + + type IsAny = 0 extends 1 & T ? Y : N; + + type Attributes = NonNullable< + { + // bumping to later TS would allow additional check for format `get${infer T}` on K + [K in keyof T]: Extract any> extends (...args: [infer X, infer Y]) => any + ? // only return true if the property value has a second argument of type ObjectInfo + IsAny ? true : never> + : never; + } extends infer A + ? // remove and key with property never + keyof Pick extends never ? never : K }[keyof A]> + : never + >; + + export type ConstructorProps = Omit & { data?: Exclude }; + export namespace ConstructorProps { + export type NonIterable

= P extends infer X ? X & Omit : never; + } export interface LayerContext { layerManager: LayerManager; @@ -1013,17 +1079,17 @@ declare module '@deck.gl/core/lib/layer' { damping: number; } export type TransitionTiming = InterpolationTransitionTiming | SpringTransitionTiming; - export interface LayerInputHandler { + export interface LayerInputHandler { (o: PickInfo, e: HammerInput): any; } export type DataSet = Iterable; export type WidthUnits = keyof typeof UNIT; - export interface ObjectInfo { + export interface ObjectInfo { // the index of the current iteration index: number; // the value of the 'data' prop on the layer. - data: DataSet | Promise> | string; + data: D extends Promise ? T : D extends string ? unknown : D; // a pre-allocated array. // the accessor function can optionally fill data into this array and // return it, instead of creating a new array for every object. @@ -1032,16 +1098,13 @@ declare module '@deck.gl/core/lib/layer' { target: T[]; } - // | AsyncIterable ToDo: Add AsyncIterable - // | { length: number } Todo: Support non-iterable objects, see deck.gl docs: /docs/developer-guide/using-layers.md#accessors - - export interface LayerProps { + export type LayerProps = Array> = { //https://deck.gl/#/documentation/deckgl-api-reference/layers/layer?section=properties id?: string; - data?: D | DataSet | Promise> | string; + data?: D; visible?: boolean; opacity?: number; - extensions?: any[]; + extensions?: E; //Interaction Properties pickable?: boolean; @@ -1079,7 +1142,17 @@ declare module '@deck.gl/core/lib/layer' { filterEnabled?: boolean; filterTransformSize?: boolean; filterTransformColor?: boolean; - } + } & ExtensionProps< + E, + BrushingExtension, + { + brushingRadius: number; + brushingEnabled?: boolean; + brushingTarget?: 'source' | 'target' | 'source_target' | 'custom'; + getBrushingTarget?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => [number, number]; + } + >; + export interface LayerChangeFlags { dataChanged: boolean | string | null; propsChanged: boolean | string | null; @@ -1104,10 +1177,22 @@ declare module '@deck.gl/core/lib/layer' { equal?: (value1: any, value2: any) => boolean; deprecatedFor?: string | string[]; } - export default class Layer = LayerProps> extends Component

{ - constructor(props: P, ...additionalProps: P[]); + export default class Layer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Component & P, S> { + constructor( + props: ConstructorProps & P, D>, + ...additionalProps: Array & P, D>> + ); + constructor( + props: ConstructorProps.NonIterable & P>, + ...additionalProps: Array & P>> + ); toString(): string; - setState(updateObject: any): void; + setState(updateObject: S): void; setNeedsRedraw(redraw?: boolean): void; setNeedsUpdate(): void; getNeedsRedraw(opts?: { clearRedrawFlags: boolean }): boolean; @@ -1141,7 +1226,7 @@ declare module '@deck.gl/core/lib/layer' { }: { info: PickInfo; mode: PickMode; - sourceLayer: Layer; + sourceLayer: Layer; }): PickInfo; invalidateAttribute(name?: string, diffReason?: string): void; updateAttributes(changedAttributes: any): void; @@ -1192,15 +1277,17 @@ declare module '@deck.gl/core/lib/layer' { } } declare module '@deck.gl/core/lib/composite-layer' { - import Layer, { LayerProps } from '@deck.gl/core/lib/layer'; + import Layer, { LayerData, LayerProps } from '@deck.gl/core/lib/layer'; import Viewport from '@deck.gl/core/viewports/viewport'; - export interface CompositeLayerProps extends LayerProps { + export type CompositeLayerProps = Array> = LayerProps & { _subLayerProps?: Object; - } - export default class CompositeLayer = CompositeLayerProps> extends Layer< - D, - P - > { + }; + export default class CompositeLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { get isComposite(): boolean; get isLoaded(): any; getSubLayers(): any; @@ -1222,7 +1309,7 @@ declare module '@deck.gl/core/lib/composite-layer' { getSubLayerClass(id: any, DefaultLayerClass: any): any; getSubLayerRow(row: any, sourceObject: any, sourceObjectIndex: any): any; getSubLayerAccessor(accessor: any): any; - getSubLayerProps = LayerProps>(sublayerProps?: {}): SP; + getSubLayerProps = LayerProps>(sublayerProps?: {}): SP; _getAttributeManager(): any; _renderLayers(): void; } @@ -1439,6 +1526,7 @@ declare module '@deck.gl/core/utils/positions' { } declare module '@deck.gl/core/views/view' { import Viewport from '@deck.gl/core/viewports/viewport'; + import { ViewStateProps } from '@deck.gl/core/lib/deck'; import { Matrix4 } from '@math.gl/core'; export interface ViewProps { @@ -1466,6 +1554,8 @@ declare module '@deck.gl/core/views/view' { modelMatrix?: Matrix4; // A model matrix to be applied to position, to match the layer props API type?: typeof Viewport; // Internal: Viewport Type + + viewState?: string | ViewStateProps; } export default class View { @@ -2109,7 +2199,7 @@ declare module '@deck.gl/core/lib/tooltip' { declare module '@deck.gl/core/lib/deck' { import Controller, { ControllerOptions } from '@deck.gl/core/controllers/controller'; import Effect from '@deck.gl/core/lib/effect'; - import Layer from '@deck.gl/core/lib/layer'; + import Layer, { LayerData } from '@deck.gl/core/lib/layer'; import LayerManager from '@deck.gl/core/lib/layer-manager'; import Tooltip from '@deck.gl/core/lib/tooltip'; import View from '@deck.gl/core/views/view'; @@ -2124,7 +2214,7 @@ declare module '@deck.gl/core/lib/deck' { isHovering: boolean; } - export interface PickInfo { + export interface PickInfo { layer: Layer; index: number; object: D; @@ -2198,8 +2288,13 @@ declare module '@deck.gl/core/lib/deck' { // https://github.com/visgl/deck.gl/blob/e948740f801cf91b541a9d7f3bba143ceac34ab2/modules/react/src/deckgl.js#L71-L72 width: string | number; height: string | number; - layers: Layer[]; - layerFilter: (args: { layer: Layer; viewport: Viewport; isPicking: boolean; renderPass: string }) => boolean; + layers: Layer[]; + layerFilter: (args: { + layer: Layer; + viewport: Viewport; + isPicking: boolean; + renderPass: string; + }) => boolean; getCursor: (interactiveState: InteractiveState) => string; views: View[]; viewState: ViewStateProps; @@ -2218,7 +2313,9 @@ declare module '@deck.gl/core/lib/deck' { canvas?: HTMLCanvasElement | string; touchAction: string; pickingRadius: number; - getTooltip: (info: PickInfo) => + getTooltip: ( + info: PickInfo + ) => | null | string | { @@ -2240,11 +2337,11 @@ declare module '@deck.gl/core/lib/deck' { onWebGLInitialized: (gl: WebGLRenderingContext) => any; onViewStateChange: (args: { viewState: any; interactionState: InteractionState; oldViewState: any }) => any; onInteractionStateChange(interactionState: InteractionState): void; - onHover: (info: PickInfo, e: MouseEvent) => any; - onClick: (info: PickInfo, e: MouseEvent) => any; - onDragStart: (info: PickInfo, e: MouseEvent) => any; - onDrag: (info: PickInfo, e: MouseEvent) => any; - onDragEnd: (info: PickInfo, e: MouseEvent) => any; + onHover: (info: PickInfo, e: MouseEvent) => any; + onClick: (info: PickInfo, e: MouseEvent) => any; + onDragStart: (info: PickInfo, e: MouseEvent) => any; + onDrag: (info: PickInfo, e: MouseEvent) => any; + onDragEnd: (info: PickInfo, e: MouseEvent) => any; onLoad: () => void; onResize: (size: { height: number; width: number }) => void; onBeforeRender: (args: { gl: WebGLRenderingContext }) => void; @@ -2585,9 +2682,16 @@ declare module '@deck.gl/core/controllers/orthographic-controller' { } } declare module '@deck.gl/core/views/orthographic-view' { - import View from '@deck.gl/core/views/view'; + import View, { ViewProps } from '@deck.gl/core/views/view'; + + interface OrthographicViewProps extends ViewProps { + far?: number; + flipY?: boolean; + near?: number; + } + export default class OrthographicView extends View { - constructor(props: any); + constructor(props: OrthographicViewProps); get controller(): any; } } @@ -2677,6 +2781,17 @@ declare module '@deck.gl/core' { export { compareProps as _compareProps } from '@deck.gl/core/lifecycle/props'; export { RGBAColor } from '@deck.gl/core/utils/color'; export { Position, Position2D, Position3D } from '@deck.gl/core/utils/positions'; + + export type TypedArray = + | Int8Array + | Uint8Array + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Uint8ClampedArray + | Float32Array + | Float64Array; } declare module '@deck.gl/core/utils/color' { export type RGBColor = [number, number, number]; diff --git a/deck.gl__extensions/index.d.ts b/deck.gl__extensions/index.d.ts index 339192c..71fffc6 100644 --- a/deck.gl__extensions/index.d.ts +++ b/deck.gl__extensions/index.d.ts @@ -182,10 +182,32 @@ declare module '@deck.gl/extensions/fill-style/fill-style' { } } declare module '@deck.gl/extensions' { + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; export { default as BrushingExtension } from '@deck.gl/extensions/brushing/brushing'; export { default as DataFilterExtension } from '@deck.gl/extensions/data-filter/data-filter'; export { default as Fp64Extension } from '@deck.gl/extensions/fp64/fp64'; export { default as PathStyleExtension } from '@deck.gl/extensions/path-style/path-style'; export { default as project64 } from '@deck.gl/extensions/fp64/project64'; export { default as FillStyleExtension } from '@deck.gl/extensions/fill-style/fill-style'; + import { Texture2D } from '@luma.gl/webgl'; + + type IsAny = 0 extends 1 & T ? Y : N; + + type ElementOf = T extends ArrayLike ? A : never; + + export type ExtensionProps | undefined, E, T> = ElementOf extends never + ? unknown + : IsAny, unknown, ElementOf extends E ? T : unknown>; + + export interface FillStyleExtensionProps { + fillPatternAtlas: string | Texture2D; + fillPatternEnabled?: boolean; + fillPatternMapping: Record; + fillPatternMask?: boolean; + getFillPattern: (d: LayerDataAccessor, objectInfo: ObjectInfo) => string; + getFillPatternScale?: number | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number); + getFillPatternOffset?: + | [number, number] + | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => [number, number]); + } } diff --git a/deck.gl__geo-layers/index.d.ts b/deck.gl__geo-layers/index.d.ts index fab7385..023d3f7 100644 --- a/deck.gl__geo-layers/index.d.ts +++ b/deck.gl__geo-layers/index.d.ts @@ -4,13 +4,18 @@ declare module '@deck.gl/geo-layers/great-circle-layer/great-circle-vertex.glsl' export default _default; } declare module '@deck.gl/geo-layers/great-circle-layer/great-circle-layer' { + import { LayerData } from '@deck.gl/core/lib/layer'; import { ArcLayerProps } from '@deck.gl/layers/arc-layer/arc-layer'; - export interface GreatCircleLayerProps extends ArcLayerProps {} + + export type GreatCircleLayerProps = Array> = ArcLayerProps; + import { ArcLayer } from '@deck.gl/layers'; export default class GreatCircleLayer< - D, - P extends GreatCircleLayerProps = GreatCircleLayerProps - > extends ArcLayer { + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends ArcLayer & P, S, E> { getShaders(): any; } } @@ -39,12 +44,19 @@ declare module '@deck.gl/geo-layers/s2-layer/s2-utils' { } declare module '@deck.gl/geo-layers/s2-layer/s2-layer' { import { CompositeLayer } from '@deck.gl/core'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; - export interface S2LayerProps extends CompositeLayerProps { - getS2Token: (d: D) => any; - } - export default class S2Layer = S2LayerProps> extends CompositeLayer { - constructor(...props: S2LayerProps[]); + + export type S2LayerProps = Array> = CompositeLayerProps & { + // Data Accessors + getS2Token: (d: LayerDataAccessor, objectInfo: ObjectInfo) => any; + }; + export default class S2Layer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { renderLayers(): any; } } @@ -191,16 +203,31 @@ declare module '@deck.gl/geo-layers/tile-layer/tile-layer' { import { CompositeLayer, Layer } from '@deck.gl/core'; import { LayerProps } from '@deck.gl/core/lib/layer'; import { ExtentsLeftBottomRightTop } from '@deck.gl/core/utils/positions'; - export interface TileLayerProps extends LayerProps { + import Tile2DHeader from '@deck.gl/geo-layers/tile-layer/tile-2d-header'; + + type BBox = { + bottom: number; + left: number; + right: number; + top: number; + }; + + type Tile = { + x: number; + y: number; + z: number; + url: string; + bbox: BBox; + signal: AbortSignal; + }; + + export type TileLayerProps< + D extends string | string[], + I extends ImageBitmap | ImageBitmap[], + E extends Array = Array + > = LayerProps & { //Data Options - getTileData?: (tile: { - x: number; - y: number; - z: number; - url: string; - bbox: any; - signal: AbortSignal; - }) => D[] | Promise | null; + getTileData?: (tile: Tile) => I | Promise | null; tileSize?: number; maxZoom?: number | null; minZoom?: number; @@ -212,48 +239,52 @@ declare module '@deck.gl/geo-layers/tile-layer/tile-layer' { extent?: ExtentsLeftBottomRightTop; //Render Options - renderSubLayers?: (props: any) => Layer | Layer[]; + renderSubLayers?: (props: { data: I; tile: Tile2DHeader & { bbox: BBox } }) => Layer | Layer[]; zRange?: [number, number]; //Callbacks - onViewportLoad?: (data: D[]) => void; - onTileLoad?: (tile: D) => void; + onViewportLoad?: (data: D) => void; + onTileLoad?: (tile: Tile) => void; onTileError?: (error: Error) => void; - } - export default class TileLayer = TileLayerProps> extends CompositeLayer { - constructor(...props: TileLayerProps[]); + }; + export default class TileLayer< + D extends string | string[], + I extends ImageBitmap | ImageBitmap[], + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { + constructor(props: TileLayerProps & P, ...additionalProps: Array & P>); initializeState(params: any): void; get isLoaded(): any; _updateTileset(): void; _onTileLoad(tile: any): void; _onTileError(error: any): void; - getTileData(tile: any): any; - renderSubLayers(props: any): any; + getTileData(tile: Tile): I | Promise | null; + renderSubLayers(props: { data: I; tile: Tile2DHeader & { bbox: BBox } }): Layer | Layer[]; renderLayers(): any; } } declare module '@deck.gl/geo-layers/trips-layer/trips-layer' { import { PathLayer } from '@deck.gl/layers'; + import { TypedArray } from '@deck.gl/core'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; - import LayerPath, { PathLayerProps, TypedArray } from '@deck.gl/layers/path-layer/path-layer'; - export interface TripsLayerProps extends PathLayerProps { + import { PathLayerProps } from '@deck.gl/layers/path-layer/path-layer'; + + export type TripsLayerProps = Array> = PathLayerProps & { //Render Options currentTime?: number; trailLength?: number; - - //Data Accessors - getPath?: (d: D) => Position[] | TypedArray; - getTimestamps?: ( - d: D, - info?: { - data: D[]; - index: number; - target: number[]; - } - ) => number[]; - } - export default class TripsLayer = TripsLayerProps> extends PathLayer { - constructor(...props: TripsLayerProps[]); + // Data Accessors + getPath?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position[] | TypedArray; + getTimestamps?: (d: LayerDataAccessor, objectInfo?: ObjectInfo) => number[]; + }; + export default class TripsLayer< + D extends LayerData>, + P = unknown, + E extends Array = Array + > extends PathLayer & P, E> { getShaders(): any; initializeState(params?: any): void; draw(params: any): void; @@ -261,28 +292,35 @@ declare module '@deck.gl/geo-layers/trips-layer/trips-layer' { } declare module '@deck.gl/geo-layers/h3-layers/h3-cluster-layer' { import { CompositeLayer } from '@deck.gl/core'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { PolygonLayerProps } from '@deck.gl/layers/polygon-layer/polygon-layer'; - export interface H3ClusterLayerProps extends PolygonLayerProps { - getHexagons?: (d: D) => string[]; - } + + export type H3ClusterLayerProps = Array> = PolygonLayerProps & { + // Data Accessors + getHexagons?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => string[]; + }; export default class H3ClusterLayer< - D, - P extends H3ClusterLayerProps = H3ClusterLayerProps - > extends CompositeLayer { - constructor(...props: H3ClusterLayerProps[]); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { renderLayers(): any; } } declare module '@deck.gl/geo-layers/h3-layers/h3-hexagon-layer' { import { CompositeLayer } from '@deck.gl/core'; + import { LayerData, LayerDataAccessor, ObjectInfo } from '@deck.gl/core/lib/layer'; import { PolygonLayerProps } from '@deck.gl/layers/polygon-layer/polygon-layer'; export function normalizeLongitudes(vertices: any, refLng: any): void; export function scalePolygon(hexId: any, vertices: any, factor: any): void; - export interface H3HexagonLayerProps extends PolygonLayerProps { + + export type H3HexagonLayerProps = Array> = PolygonLayerProps & { highPrecision?: boolean; coverage?: number; - getHexagon?: (d: D) => string; - } + // Data Accessors + getHexagon?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => string; + }; /** * A subclass of HexagonLayer that uses H3 hexagonIds in data objects @@ -296,10 +334,11 @@ declare module '@deck.gl/geo-layers/h3-layers/h3-hexagon-layer' { * index !== -1 to see if picking matches an actual object. */ export default class H3HexagonLayer< - D, - P extends H3HexagonLayerProps = H3HexagonLayerProps - > extends CompositeLayer { - constructor(...props: H3HexagonLayerProps[]); + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { _shouldUseHighPrecision(): any; _updateVertices(viewport: any): void; renderLayers(): any; @@ -334,13 +373,12 @@ declare module '@deck.gl/geo-layers/tile-3d-layer/tile-3d-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export interface Tile3DLayerProps extends CompositeLayerProps { + export type Tile3DLayerProps = Array> = CompositeLayerProps & { //Render Options opacity?: number; pointSize?: number; //Data Properties - data?: string; loader?: any; pickable?: boolean; @@ -352,12 +390,13 @@ declare module '@deck.gl/geo-layers/tile-3d-layer/tile-3d-layer' { onTileLoad?: (tileHeader: Object) => void; onTileUnload?: (tileHeader: Object) => void; onTileError?: (tileHeader: Object, url: string, message: string) => void; - } - export default class Tile3DLayer = Tile3DLayerProps> extends CompositeLayer< - D, - P - > { - constructor(...props: Tile3DLayerProps[]); + }; + export default class Tile3DLayer< + D extends string, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(params: any): void; _loadTileset(tilesetUrl: any): Promise; _onTileLoad(tileHeader: any): void; @@ -373,6 +412,7 @@ declare module '@deck.gl/geo-layers/tile-3d-layer/tile-3d-layer' { declare module '@deck.gl/geo-layers/terrain-layer/terrain-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; + import { LayerData } from '@deck.gl/core/lib/layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { ExtentsLeftBottomRightTop } from '@deck.gl/core/utils/positions'; /** @@ -382,7 +422,7 @@ declare module '@deck.gl/geo-layers/terrain-layer/terrain-layer' { * } */ - export interface TerrainLayerProps extends CompositeLayerProps { + export type TerrainLayerProps = Array> = CompositeLayerProps & { //Data Options elevationData: string | string[]; texture?: string | null; @@ -408,12 +448,13 @@ declare module '@deck.gl/geo-layers/terrain-layer/terrain-layer' { maxZoom?: number | null; tileSize?: number; extent?: ExtentsLeftBottomRightTop; - } - export default class TerrainLayer = TerrainLayerProps> extends CompositeLayer< - D, - P - > { - constructor(...props: TerrainLayerProps[]); + }; + export default class TerrainLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { loadTerrain({ elevationData, bounds, @@ -466,14 +507,41 @@ declare module '@deck.gl/geo-layers/mvt-layer/clip-extension' { } declare module '@deck.gl/geo-layers/mvt-layer/mvt-layer' { import TileLayer, { TileLayerProps } from '@deck.gl/geo-layers/tile-layer/tile-layer'; - export interface MVTLayerProps extends TileLayerProps { + + type TileJson = { + tilejson: string; + name?: string; + description?: string; + version?: string; + attribution?: string; + template?: string; + legend?: string; + scheme?: string; + tiles: string[]; + grid?: string[]; + data?: string[]; + minzoom?: number; + maxzoom?: number; + bounds?: [number, number, number, number]; + center?: [number, number, number]; + }; + + export type MVTLayerProps< + D extends string | string[] | TileJson, + I extends ImageBitmap | ImageBitmap[], + E extends Array = Array + > = Omit, I, E>, 'data'> & { + data?: D; uniqueIdProperty?: string; binary?: boolean; - } - export default class MVTLayer = MVTLayerProps> extends TileLayer { - constructor(...props: MVTLayerProps[]); - getTileData(tile: any): any; - renderSubLayers(props: any): any; + }; + export default class MVTLayer< + D extends string | string[] | TileJson, + I extends ImageBitmap | ImageBitmap[], + P = unknown, + E extends Array = Array + > extends TileLayer, I, MVTLayerProps & P, E> { + constructor(props: MVTLayerProps & P); } } declare module '@deck.gl/geo-layers' { diff --git a/deck.gl__layers/index.d.ts b/deck.gl__layers/index.d.ts index fcf61ce..d03e0f2 100644 --- a/deck.gl__layers/index.d.ts +++ b/deck.gl__layers/index.d.ts @@ -8,26 +8,31 @@ declare module '@deck.gl/layers/arc-layer/arc-layer-fragment.glsl' { export default _default; } declare module '@deck.gl/layers/arc-layer/arc-layer' { - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface ArcLayerProps extends LayerProps { + + export type ArcLayerProps = Array> = LayerProps & { widthUnits?: string; widthScale?: number; widthMinPixels?: number; widthMaxPixels?: number; - - //Data Accessors - getSourcePosition?: (d: D) => Position; - getTargetPosition?: (d: D) => Position; - getSourceColor?: ((d: D) => RGBAColor) | RGBAColor; - getTargetColor?: ((d: D) => RGBAColor) | RGBAColor; - getWidth?: ((d: D) => number) | number; - getHeight?: ((d: D) => number) | number; - getTilt?: ((d: D) => number) | number; - } + // Data Accessors + getSourcePosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getTargetPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getSourceColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getTargetColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getHeight?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getTilt?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + }; import { Layer } from '@deck.gl/core'; - export default class ArcLayer = ArcLayerProps> extends Layer { + export default class ArcLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -47,9 +52,16 @@ declare module '@deck.gl/layers/bitmap-layer/bitmap-layer' { import { LayerProps } from '@deck.gl/core/lib/layer'; import { RGBAColor, RGBColor } from '@deck.gl/core/utils/color'; import { Position, ExtentsLeftBottomRightTop } from '@deck.gl/core/utils/positions'; - export interface BitmapLayerProps extends LayerProps { + import { Texture2D, Texture2DProps } from '@luma.gl/webgl'; + + type Image = string | Texture2D | ImageBitmap | ImageData | HTMLCanvasElement | HTMLVideoElement | Texture2DProps; + + export type BitmapLayerProps = Array> = Omit< + LayerProps, + 'data' + > & { //Data - image: any; + image: I; bounds: ExtentsLeftBottomRightTop | [Position, Position, Position, Position]; loadOptions?: any; @@ -60,8 +72,14 @@ declare module '@deck.gl/layers/bitmap-layer/bitmap-layer' { desaturate?: number; transparentColor?: RGBAColor; tintColor?: RGBColor; - } - export default class BitmapLayer = BitmapLayerProps> extends Layer { + }; + export default class BitmapLayer< + I extends Image, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { + constructor(props: BitmapLayerProps & P); getShaders(): any; initializeState(params: any): void; finalizeState(): void; @@ -151,9 +169,9 @@ declare module '@deck.gl/layers/icon-layer/icon-manager' { } declare module '@deck.gl/layers/icon-layer/icon-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps, WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; import { Position, Position2D } from '@deck.gl/core/utils/positions'; - import Texture2D from '@luma.gl/webgl/classes/texture-2d'; + import { Texture2D } from '@luma.gl/webgl'; import { RGBAColor } from '@deck.gl/core/utils/color'; export interface IconDefinitionBase { @@ -188,7 +206,7 @@ declare module '@deck.gl/layers/icon-layer/icon-layer' { [key: string]: IconDefinition; } - export interface IconLayerProps extends LayerProps { + export type IconLayerProps = Array> = LayerProps & { iconAtlas?: Texture2D | string; iconMapping?: IconMapping; sizeScale?: number; @@ -197,17 +215,24 @@ declare module '@deck.gl/layers/icon-layer/icon-layer' { sizeMaxPixels?: number; billboard?: boolean; alphaCutoff?: number; + // Data Accessors + getIcon?: ( + x: LayerDataAccessor, + objectInfo: ObjectInfo + ) => string | ({ url: string; id?: string } & IconDefinitionBase); + getPosition?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => Position) | Position; + getSize?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getColor?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getAngle?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getPixelOffset?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => Position2D) | Position2D; + }; - //Data Accessors - getIcon?: (x: D) => string | ({ url: string; id?: string } & IconDefinitionBase); - getPosition?: (x: D) => Position; - getSize?: ((x: D) => number) | number; - getColor?: ((x: D) => RGBAColor) | RGBAColor; - getAngle?: ((x: D) => number) | number; - getPixelOffset?: ((x: D) => Position2D) | Position2D; - } - - export default class IconLayer = IconLayerProps> extends Layer { + export default class IconLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; get isLoaded(): any; @@ -230,22 +255,27 @@ declare module '@deck.gl/layers/line-layer/line-layer-fragment.glsl' { } declare module '@deck.gl/layers/line-layer/line-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps, WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface LineLayerProps extends LayerProps { + + export type LineLayerProps = Array> = LayerProps & { widthUnits?: WidthUnits; widthScale?: number; widthMinPixels?: number; widthMaxPixels?: number; - - //Data Accessors - getSourcePosition?: (d: D) => Position; - getTargetPosition?: (d: D) => Position; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - getWidth?: ((d: D) => number) | number; - } - export default class LineLayer = LineLayerProps> extends Layer { + // Data Accessors + getSourcePosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getTargetPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + }; + export default class LineLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -262,21 +292,27 @@ declare module '@deck.gl/layers/point-cloud-layer/point-cloud-layer-fragment.gls } declare module '@deck.gl/layers/point-cloud-layer/point-cloud-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { Position } from '@deck.gl/core/utils/positions'; - export interface PointCloudLayerProps extends LayerProps { + + export type PointCloudLayerProps = Array> = LayerProps & { sizeUnits?: string; pointSize?: number; material?: any; - getPosition?: (d: D) => Position; - getNormal?: ((d: D) => [number, number, number]) | [number, number, number]; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - } - export default class PointCloudLayer = PointCloudLayerProps> extends Layer< - D, - P - > { + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getNormal?: + | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => [number, number, number]) + | [number, number, number]; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + }; + export default class PointCloudLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(id: any): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -293,11 +329,13 @@ declare module '@deck.gl/layers/scatterplot-layer/scatterplot-layer-fragment.gls } declare module '@deck.gl/layers/scatterplot-layer/scatterplot-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps, WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { UNIT } from '@deck.gl/core/lib/constants'; - export interface ScatterplotLayerProps extends LayerProps { + import { ExtensionProps, FillStyleExtension, FillStyleExtensionProps } from '@deck.gl/extensions'; + + export type ScatterplotLayerProps = Array> = LayerProps & { radiusScale?: number; lineWidthUnits?: WidthUnits; lineWidthScale?: number; @@ -308,19 +346,20 @@ declare module '@deck.gl/layers/scatterplot-layer/scatterplot-layer' { lineWidthMinPixels?: number; lineWidthMaxPixels?: number; radiusUnits?: keyof typeof UNIT; - - //Data Accessors - getPosition?: (d: D) => Position; - getRadius?: ((d: D) => number) | number; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - getFillColor?: ((d: D) => RGBAColor) | RGBAColor; - getLineColor?: ((d: D) => RGBAColor) | RGBAColor; - getLineWidth?: ((d: D) => number) | number; - } - export default class ScatterplotLayer = ScatterplotLayerProps> extends Layer< - D, - P - > { + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getRadius?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getFillColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps>; + export default class ScatterplotLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(id: any): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -344,10 +383,12 @@ declare module '@deck.gl/layers/column-layer/column-layer-fragment.glsl' { declare module '@deck.gl/layers/column-layer/column-layer' { import { Layer } from '@deck.gl/core'; import ColumnGeometry from '@deck.gl/layers/column-layer/column-geometry'; - import { LayerProps, WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; import { Position, Position2D } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export interface ColumnLayerProps extends LayerProps { + import { ExtensionProps, FillStyleExtension, FillStyleExtensionProps } from '@deck.gl/extensions'; + + export type ColumnLayerProps = Array> = LayerProps & { diskResolution?: number; radius?: number; angle?: number; @@ -364,13 +405,19 @@ declare module '@deck.gl/layers/column-layer/column-layer' { lineWidthMinPixels?: number; lineWidthMaxPixels?: number; material?: any; - getPosition?: (d: D) => Position; - getFillColor?: ((d: D) => RGBAColor) | RGBAColor; - getLineColor?: ((d: D) => RGBAColor) | RGBAColor; - getElevation?: ((d: D) => number) | number; - getLineWidth?: ((d: D) => number) | number; - } - export default class ColumnLayer = ColumnLayerProps> extends Layer { + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position; + getFillColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getElevation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getLineWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps>; + export default class ColumnLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; /** * DeckGL calls initializeState when GL context is available @@ -385,25 +432,27 @@ declare module '@deck.gl/layers/column-layer/column-layer' { } declare module '@deck.gl/layers/column-layer/grid-cell-layer' { import ColumnLayer from '@deck.gl/layers/column-layer/column-layer'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { Position2D } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export interface GridCellLayerProps extends LayerProps { + + export type GridCellLayerProps = Array> = LayerProps & { cellSize?: number; coverage?: number; elevationScale?: number; extruded?: boolean; material?: any; - - //Data Accessors - getPosition?: (d: D) => Position2D; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - getElevation?: ((d: D) => number) | number; - } - export default class GridCellLayer = GridCellLayerProps> extends ColumnLayer< - D, - P - > { + // Data Accessors + getPosition?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position2D; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getElevation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + }; + export default class GridCellLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends ColumnLayer & P, S, E> { getGeometry(diskResolution: any): any; draw({ uniforms }: { uniforms: any }): void; } @@ -432,21 +481,14 @@ declare module '@deck.gl/layers/path-layer/path-layer-fragment.glsl' { export default _default; } declare module '@deck.gl/layers/path-layer/path-layer' { - import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { Layer, TypedArray } from '@deck.gl/core'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export type TypedArray = - | Int8Array - | Uint8Array - | Int16Array - | Uint16Array - | Int32Array - | Uint32Array - | Uint8ClampedArray - | Float32Array - | Float64Array; - export interface PathLayerProps extends LayerProps { + import { ExtensionProps, PathStyleExtension } from '@deck.gl/extensions'; + + export type PathLayerProps = Array> = LayerProps & { + extensions?: E; widthUnits?: string; widthScale?: number; widthMinPixels?: number; @@ -456,14 +498,28 @@ declare module '@deck.gl/layers/path-layer/path-layer' { billboard?: boolean; miterLimit?: number; _pathType?: 'loop' | 'open'; - - //Data Accessors - getPath?: (d: D) => Position[] | TypedArray; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - getWidth?: ((d: D) => number) | number; - } - export default class PathLayer = PathLayerProps> extends Layer { - constructor(props: PathLayerProps); + // Data Accessors + getPath?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => Position[] | TypedArray; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps< + E, + PathStyleExtension, + { + dashGapPickable?: boolean; + dashJustified?: boolean; + getDashArray?: + | [number, number] + | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => [number, number]); + getOffset?: number | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number); + } + >; + export default class PathLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -561,27 +617,30 @@ declare module '@deck.gl/layers/solid-polygon-layer/solid-polygon-layer-fragment } declare module '@deck.gl/layers/solid-polygon-layer/solid-polygon-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export interface SolidPolygonLayerProps extends LayerProps { + import { ExtensionProps, FillStyleExtension, FillStyleExtensionProps } from '@deck.gl/extensions'; + + export type SolidPolygonLayerProps = Array> = LayerProps & { filled?: boolean; extruded?: boolean; wireframe?: boolean; elevationScale?: number; material?: any; _normalize?: boolean; - - //Data Accessors - getPolygon?: (x: D) => Position[] | Position[][]; - getFillColor?: ((x: D) => RGBAColor) | RGBAColor; - getLineColor?: ((x: D) => RGBAColor) | RGBAColor; - getElevation?: ((x: D) => number) | number; - } + // Data Accessors + getPolygon?: (x: LayerDataAccessor, objectInfo: ObjectInfo) => Position[] | Position[][]; + getFillColor?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineColor?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getElevation?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps>; export default class SolidPolygonLayer< - D, - P extends SolidPolygonLayerProps = SolidPolygonLayerProps - > extends Layer { + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(vs: any): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -615,10 +674,12 @@ declare module '@deck.gl/layers/utils' { declare module '@deck.gl/layers/polygon-layer/polygon-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; - import { WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; import { Position } from '@deck.gl/core/utils/positions'; import { RGBAColor } from '@deck.gl/core/utils/color'; - export interface PolygonLayerProps extends CompositeLayerProps { + import { ExtensionProps, FillStyleExtension, FillStyleExtensionProps } from '@deck.gl/extensions'; + + export type PolygonLayerProps = Array> = CompositeLayerProps & { filled?: boolean; stroked?: boolean; extruded?: boolean; @@ -632,18 +693,19 @@ declare module '@deck.gl/layers/polygon-layer/polygon-layer' { lineMiterLimit?: number; material?: any; _normalize?: boolean; - - //Data Accessors - getPolygon?: (x: D) => Position[] | Position[][]; - getFillColor?: ((x: D) => RGBAColor) | RGBAColor; - getLineColor?: ((x: D) => RGBAColor) | RGBAColor; - getLineWidth?: ((x: D) => number) | number; - getElevation?: ((x: D) => number) | number; - } - export default class PolygonLayer = PolygonLayerProps> extends CompositeLayer< - D, - P - > { + // Data Accessors + getPolygon?: (x: LayerDataAccessor, objectInfo: ObjectInfo) => Position[] | Position[][]; + getFillColor?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineColor?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getLineWidth?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getElevation?: ((x: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps>; + export default class PolygonLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(params: any): void; _getPaths(dataRange?: {}): any[]; renderLayers(): any[]; @@ -678,9 +740,12 @@ declare module '@deck.gl/layers/geojson-layer/geojson' { declare module '@deck.gl/layers/geojson-layer/geojson-layer' { import { CompositeLayer } from '@deck.gl/core'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; + import { LayerData, LayerDataAccessor } from '@deck.gl/core/lib/layer'; import { RGBAColor } from '@deck.gl/core/utils/color'; - import { WidthUnits } from '@deck.gl/core/lib/layer'; - export interface GeoJsonLayerProps extends CompositeLayerProps { + import { ObjectInfo, WidthUnits } from '@deck.gl/core/lib/layer'; + import { ExtensionProps, FillStyleExtension, FillStyleExtensionProps } from '@deck.gl/extensions'; + + export type GeoJsonLayerProps = Array> = CompositeLayerProps & { //Render Options filled?: boolean; stroked?: boolean; @@ -698,21 +763,21 @@ declare module '@deck.gl/layers/geojson-layer/geojson-layer' { pointRadiusMinPixels?: number; pointRadiusMaxPixels?: number; material?: any; - - //Data Accessors - getLineColor?: ((d: D) => RGBAColor) | RGBAColor; - getFillColor?: ((d: D) => RGBAColor) | RGBAColor; - getPointRadius?: ((d: D) => number) | number; - getLineWidth?: ((d: D) => number) | number; - getElevation?: ((d: D) => number) | number; - - // getRadius is deprecated since deck.gl v8.5, use getPointRadius instead - getRadius?: ((d: D) => number) | number; - } - export default class GeoJsonLayer = GeoJsonLayerProps> extends CompositeLayer< - D, - P - > { + // Data Accessors + getLineColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getFillColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getPointRadius?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getLineWidth?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getElevation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + /** @deprecated since deck.gl v8.5, use getPointRadius instead */ + getRadius?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + } & ExtensionProps>; + export default class GeoJsonLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(params: any): void; renderLayers(): any[]; _getHighlightedIndex(data: any): any; @@ -723,8 +788,14 @@ declare module '@deck.gl/layers/text-layer/multi-icon-layer/multi-icon-layer-fra export default _default; } declare module '@deck.gl/layers/text-layer/multi-icon-layer/multi-icon-layer' { - import IconLayer from '@deck.gl/layers/icon-layer/icon-layer'; - export default class MultiIconLayer extends IconLayer { + import { LayerData } from '@deck.gl/core/lib/layer'; + import IconLayer, { IconLayerProps } from '@deck.gl/layers/icon-layer/icon-layer'; + export default class MultiIconLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends IconLayer & P, S, E> { getShaders(): any; initializeState(params: any): void; draw({ uniforms }: { uniforms: any }): void; @@ -890,11 +961,13 @@ declare module '@deck.gl/layers/text-layer/text-layer' { import { FontSettings } from '@deck.gl/layers/text-layer/font-atlas-manager'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { CompositeLayerProps } from '@deck.gl/core/lib/composite-layer'; - import { WidthUnits } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, WidthUnits } from '@deck.gl/core/lib/layer'; + import { Position } from '@deck.gl/core/utils/positions'; export type TextAnchor = 'start' | 'middle' | 'end'; export type AlignmentBaseline = 'top' | 'center' | 'bottom'; + import { ObjectInfo } from '@deck.gl/core/lib/layer'; - export interface TextLayerProps extends CompositeLayerProps { + export type TextLayerProps = Array> = CompositeLayerProps & { sizeScale?: number; sizeUnits?: WidthUnits; sizeMinPixels?: number; @@ -910,22 +983,29 @@ declare module '@deck.gl/layers/text-layer/text-layer' { fontSettings?: FontSettings; wordBreak?: 'break-all' | 'break-word'; maxWidth?: number; - - //Data Accessors - getText?: (x: D) => string; - getPosition?: (x: D) => [number, number]; - getSize?: ((x: D) => number) | number; - getColor?: ((x: D) => RGBAColor) | RGBAColor; - getAngle?: ((x: D) => number) | number; - - //Text Alignment Options - getTextAnchor?: ((x: D) => TextAnchor) | TextAnchor; - getAlignmentBaseline?: ((x: D) => AlignmentBaseline) | AlignmentBaseline; - getPixelOffset?: ((x: D) => number[]) | number[]; outlineColor?: RGBAColor; outlineWidth?: number; - } - export default class TextLayer = TextLayerProps> extends CompositeLayer { + // Data Accessors + getText?: (d: LayerDataAccessor, objectInfo: ObjectInfo) => string; + getPosition?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => Position) | Position; + getSize?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getAngle?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number) | number; + + //Text Alignment Options + getTextAnchor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => TextAnchor) | TextAnchor; + getAlignmentBaseline?: + | ((d: LayerDataAccessor, objectInfo: ObjectInfo) => AlignmentBaseline) + | AlignmentBaseline; + getPixelOffset?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number[]) | number[]; + }; + + export default class TextLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends CompositeLayer & P, S, E> { initializeState(params: any): void; finalizeState(): void; _updateFontAtlas(oldProps: any, props: any): void; diff --git a/deck.gl__mapbox/index.d.ts b/deck.gl__mapbox/index.d.ts index 3006dc1..b25ca3d 100644 --- a/deck.gl__mapbox/index.d.ts +++ b/deck.gl__mapbox/index.d.ts @@ -8,18 +8,18 @@ declare module '@deck.gl/mapbox/deck-utils' { } declare module '@deck.gl/mapbox/mapbox-layer' { import { Deck, Layer } from 'deck.gl'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerProps } from '@deck.gl/core/lib/layer'; export type RenderingMode = '2d' | '3d'; - export interface MapboxLayerProps extends LayerProps { + export interface MapboxLayerProps extends LayerProps { id: string; deck?: Deck; renderingMode?: RenderingMode; type?: typeof Layer; } - export default class MapboxLayer { + export default class MapboxLayer { constructor(props: MapboxLayerProps); id: string; diff --git a/deck.gl__mesh-layers/index.d.ts b/deck.gl__mesh-layers/index.d.ts index 1d151c2..ecc9f64 100644 --- a/deck.gl__mesh-layers/index.d.ts +++ b/deck.gl__mesh-layers/index.d.ts @@ -44,7 +44,7 @@ declare module '@deck.gl/mesh-layers/simple-mesh-layer/simple-mesh-layer-fragmen } declare module '@deck.gl/mesh-layers/simple-mesh-layer/simple-mesh-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo} from '@deck.gl/core/lib/layer'; import Texture2D from '@luma.gl/webgl/classes/texture-2d'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { Position3D, PitchYawRoll, ScaleXYZ, TranslationXYZ } from '@deck.gl/core/utils/positions'; @@ -59,29 +59,27 @@ declare module '@deck.gl/mesh-layers/simple-mesh-layer/simple-mesh-layer' { shininess?: number; specularColor?: [number, number, number]; } - export interface AccessorContext { - index: number; - data: D; - target: Array; - } - export interface SimpleMeshLayerProps extends LayerProps { + export type SimpleMeshLayerProps = Array> = LayerProps & { mesh: SimpleMesh | null; _instanced?: boolean; // _instanced is a hack to use world position instead of meter offsets in mesh texture?: Texture2D | HTMLImageElement | string | null; sizeScale?: number; wireframe?: boolean; material?: Material; - getPosition?: ((d: D, context: AccessorContext) => Position3D) | Position3D; - getColor?: ((d: D, context: AccessorContext) => RGBAColor) | RGBAColor; - getOrientation?: ((d: D, context: AccessorContext) => PitchYawRoll) | PitchYawRoll; - getScale?: ((d: D, context: AccessorContext) => ScaleXYZ) | ScaleXYZ; // Scaling factor on the mesh along each axis. - getTranslation?: ((d: D, context: AccessorContext) => TranslationXYZ) | TranslationXYZ; // Translation of the mesh along each axis. Offset from the center position given by getPosition. [x, y, z] in meters. - getTransformMatrix?: ((d: D, context: AccessorContext) => number[] | null) | number[] | null; // 4x4 column-major model matrix - } - export default class SimpleMeshLayer = SimpleMeshLayerProps> extends Layer< - D, - P - > { + // Data Accessors + getPosition?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => Position3D) | Position3D; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getOrientation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => PitchYawRoll) | PitchYawRoll; + getScale?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => ScaleXYZ) | ScaleXYZ; // Scaling factor on the mesh along each axis. + getTranslation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => TranslationXYZ) | TranslationXYZ; // Translation of the mesh along each axis. Offset from the center position given by getPosition. [x, y, z] in meters. + getTransformMatrix?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number[] | null) | number[] | null; // 4x4 column-major model matrix + }; + export default class SimpleMeshLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { getShaders(): any; initializeState(params: any): void; finalizeState(): void; @@ -103,11 +101,12 @@ declare module '@deck.gl/mesh-layers/scenegraph-layer/scenegraph-layer-fragment. } declare module '@deck.gl/mesh-layers/scenegraph-layer/scenegraph-layer' { import { Layer } from '@deck.gl/core'; - import { LayerProps } from '@deck.gl/core/lib/layer'; + import { LayerData, LayerDataAccessor, LayerProps, ObjectInfo } from '@deck.gl/core/lib/layer'; import { ScenegraphNode } from '@luma.gl/experimental'; import { RGBAColor } from '@deck.gl/core/utils/color'; import { Position3D, PitchYawRoll, ScaleXYZ, TranslationXYZ } from '@deck.gl/core/utils/positions'; - export interface ScenegraphLayerProps extends LayerProps { + + export type ScenegraphLayerProps = Array> = LayerProps & { //Mesh scenegraph: URL | ScenegraphNode | Promise; @@ -119,23 +118,24 @@ declare module '@deck.gl/mesh-layers/scenegraph-layer/scenegraph-layer' { _lighting?: string; //Data Accessors - getPosition?: ((d: D) => Position3D) | Position3D; - getColor?: ((d: D) => RGBAColor) | RGBAColor; - getOrientation?: ((d: D) => PitchYawRoll) | PitchYawRoll; - getScale?: ((d: D) => ScaleXYZ) | ScaleXYZ; // Scaling factor on the mesh along each axis. - getTranslation?: ((d: D) => TranslationXYZ) | TranslationXYZ; // Translation of the mesh along each axis. Offset from the center position given by getPosition. [x, y, z] in meters. - getTransformMatrix?: ((d: D) => number[][]) | number[][]; // 4x4 column-major model matrix sizeMinPixels?: number; sizeMaxPixels?: number; + getPosition?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => Position3D) | Position3D; + getColor?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => RGBAColor) | RGBAColor; + getOrientation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => PitchYawRoll) | PitchYawRoll; + getScale?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => ScaleXYZ) | ScaleXYZ; // Scaling factor on the mesh along each axis. + getTranslation?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => TranslationXYZ) | TranslationXYZ; // Translation of the mesh along each axis. Offset from the center position given by getPosition. [x, y, z] in meters. + getTransformMatrix?: ((d: LayerDataAccessor, objectInfo: ObjectInfo) => number[][]) | number[][]; // 4x4 column-major model matrix //Experimental _imageBasedLightingEnvironment?: any; - } - export default class ScenegraphLayer = ScenegraphLayerProps> extends Layer< - D, - P - > { - constructor(props: ScenegraphLayerProps); + }; + export default class ScenegraphLayer< + D extends LayerData>, + P = unknown, + S = any, + E extends Array = Array + > extends Layer & P, S, E> { initializeState(params: any): void; finalizeState(): void; _updateScenegraph(props: any): void; diff --git a/package.json b/package.json index 355eda0..7a938d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@danmarshall/deckgl-typings", - "version": "4.9.21", + "version": "5.0.0", "description": "TypeScript declaration files for deck.gl", "types": "deck.gl/index.d.ts", "scripts": { diff --git a/test/@deck.gl/aggregation-layers.d.ts b/test/@deck.gl/aggregation-layers.d.ts deleted file mode 100644 index 75dd11c..0000000 --- a/test/@deck.gl/aggregation-layers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// - -import { AGGREGATION_OPERATION, CPUGridLayer } from '@deck.gl/aggregation-layers'; diff --git a/test/@deck.gl/aggregation-layers.ts b/test/@deck.gl/aggregation-layers.ts new file mode 100644 index 0000000..26ed991 --- /dev/null +++ b/test/@deck.gl/aggregation-layers.ts @@ -0,0 +1,52 @@ +import { GPUGridLayer } from 'deck.gl'; + +import { DataFilterExtension } from '@deck.gl/extensions'; + +new GPUGridLayer({ + data: { + attributes: { getColorWeight: new Int8Array(), getFilterValue: new Int8Array() }, + length: 4, + }, + extensions: [new DataFilterExtension()], + filterRange: [2, 2], + getFilterValue: () => { + return [1, 1]; + }, +}); + +new GPUGridLayer({ + data: { + attributes: { + getColorWeight: new Int8Array(), + // @ts-expect-error -- DataFilterExtension not installed + getFilterValue: new Int8Array(), + }, + length: 4, + }, +}); + +new GPUGridLayer({ + extensions: [new DataFilterExtension()], + filterRange: [2, 2], + getFilterValue() { + return [2]; + }, +}); +// @ts-expect-error -- expecting filterRange and getFilterValue +new GPUGridLayer({ extensions: [new DataFilterExtension()] }); +new GPUGridLayer({ + extensions: [], + // @ts-expect-error -- DataFilterExtension not installed + filterRange: [2, 2], + getFilterValue() { + return [2]; + }, +}); +new GPUGridLayer({ + extensions: [], + filterRange: [2, 2], + getFilterValue() { + return [2]; + }, +}); +new GPUGridLayer({}); diff --git a/test/@deck.gl/ensure-consistent-layer-interfaces.ts b/test/@deck.gl/ensure-consistent-layer-interfaces.ts index 35d6a40..57c81ce 100644 --- a/test/@deck.gl/ensure-consistent-layer-interfaces.ts +++ b/test/@deck.gl/ensure-consistent-layer-interfaces.ts @@ -1,4 +1,5 @@ import { Layer } from 'deck.gl'; +import { LayerData } from '@deck.gl/core/lib/layer'; import { ArcLayer, BitmapLayer, @@ -35,7 +36,7 @@ import { } from '@deck.gl/geo-layers'; import { SimpleMeshLayer, ScenegraphLayer } from '@deck.gl/mesh-layers'; -interface Datum {} +type Datum = LayerData; export const testLayersArray: Layer[] = [ // @ts-expect-error - Should have at least one prop object to constructor @@ -45,7 +46,7 @@ export const testLayersArray: Layer[] = [ // Multiple prop objects to constructor new Layer({}, {}, {}, {}, {}), new ArcLayer({}), - new BitmapLayer({ + new BitmapLayer({ image: null, bounds: [0, 0, 0, 0], }), @@ -74,11 +75,11 @@ export const testLayersArray: Layer[] = [ new H3ClusterLayer({}), new H3HexagonLayer({}), new TripsLayer({}), - new Tile3DLayer({}), + new Tile3DLayer({}), new TerrainLayer({ elevationData: '', }), - new MVTLayer({}), + new MVTLayer({}), new SimpleMeshLayer({ mesh: { positions: new Float32Array(), diff --git a/test/@deck.gl/extensions.d.ts b/test/@deck.gl/extensions.d.ts deleted file mode 100644 index 153dfbd..0000000 --- a/test/@deck.gl/extensions.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// - -import { BrushingExtension, DataFilterExtension, Fp64Extension } from '@deck.gl/extensions'; diff --git a/test/@deck.gl/extensions.ts b/test/@deck.gl/extensions.ts new file mode 100644 index 0000000..a80221d --- /dev/null +++ b/test/@deck.gl/extensions.ts @@ -0,0 +1,54 @@ +import { GPUGridLayer, Layer, PathLayer, ScatterplotLayer } from 'deck.gl'; +import { BrushingExtension, DataFilterExtension, FillStyleExtension, PathStyleExtension } from '@deck.gl/extensions'; + +var withBrushingExtension: Layer; +withBrushingExtension.props.brushingRadius; +// @ts-expect-error +withBrushingExtension.props.filterRange; +// @ts-expect-error +withBrushingExtension.props.fillPatternEnabled; +// @ts-expect-error +withBrushingExtension.props.getDashArray; + +var withoutBrushingExtension: Layer; +// @ts-expect-error +withoutBrushingExtension.props.brushingRadius; + +var withDataFilterExtension: GPUGridLayer; +withDataFilterExtension.props.filterRange; +// @ts-expect-error +withDataFilterExtension.props.brushingRadius; +// @ts-expect-error +withDataFilterExtension.props.fillPatternEnabled; +// @ts-expect-error +withDataFilterExtension.props.getDashArray; + +var withoutDataFilterExtension: GPUGridLayer; +// @ts-expect-error +withoutDataFilterExtension.props.filterRange; + +var withFillStyleExtension: ScatterplotLayer; +withFillStyleExtension.props.fillPatternEnabled; +// @ts-expect-error +withFillStyleExtension.props.brushingRadius; +// @ts-expect-error +withFillStyleExtension.props.filterRange; +// @ts-expect-error +withFillStyleExtension.props.getDashArray; + +var withoutFillStyleExtension: ScatterplotLayer; +// @ts-expect-error +withoutFillStyleExtension.props.fillPatternEnabled; + +var withPathStyleExtension: PathLayer; +withPathStyleExtension.props.getDashArray; +// @ts-expect-error +withPathStyleExtension.props.brushingRadius; +// @ts-expect-error +withPathStyleExtension.props.filterRange; +// @ts-expect-error +withPathStyleExtension.props.fillPatternEnabled; + +var withoutPathStyleExtension: PathLayer; +// @ts-expect-error +withoutPathStyleExtension.props.getDashArray; diff --git a/test/@deck.gl/layers.d.ts b/test/@deck.gl/layers.d.ts deleted file mode 100644 index 9f6788f..0000000 --- a/test/@deck.gl/layers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// - -import { ArcLayer, BitmapLayer, ColumnLayer } from '@deck.gl/layers'; diff --git a/test/@deck.gl/layers.ts b/test/@deck.gl/layers.ts new file mode 100644 index 0000000..f00f54d --- /dev/null +++ b/test/@deck.gl/layers.ts @@ -0,0 +1,182 @@ +import { BitmapLayer, ColumnLayer, GridCellLayer, ScatterplotLayer, TextLayer } from 'deck.gl'; + +import { BrushingExtension } from '@deck.gl/extensions'; +import { LayerData } from '@deck.gl/core/lib/layer'; +import { ScatterplotLayerProps } from '@deck.gl/layers'; +import { Buffer as LumaBuffer } from '@luma.gl/webgl'; + +var unknownArg: unknown; + +new TextLayer({}).props.getText(unknownArg, { index: 1, data: [1], target: ['d'] }); + +var numberArg: number; + +new TextLayer({ data: [1] }).props.getText(numberArg, { index: 1, data: [1], target: ['d'] }); + +// @ts-expect-error -- datum is number +new TextLayer({ data: [1] }).props.getText(unknownArg, { index: 1, data: [1], target: ['d'] }); + +new TextLayer({ + brushingRadius: 4, + data: { attributes: { getPosition: new Int8Array(), getSize: new Uint16Array() }, length: 4 }, + extensions: [new BrushingExtension()], +}); + +new TextLayer({ + data: { attributes: { getPosition: new Int8Array(), getSize: new Uint16Array() }, length: 4, zExtraAttribute: true }, + extensions: [], +}); + +new TextLayer({ + data: { + attributes: { getPosition: { size: 2, stride: 1, value: new Int8Array() } }, + length: 4, + zExtraAttribute: true, + }, +}); + +new TextLayer({ + data: { + attributes: { getPosition: new LumaBuffer(new WebGLRenderingContext(), new Int8Array()) }, + length: 4, + zExtraAttribute: true, + }, +}); + +// @ts-expect-error -- attributes contains unknown property +new TextLayer({ data: { attributes: { NotAnAttribute: new Int8Array() }, length: 4 } }); + +// @ts-expect-error -- attributes contains a non-accessor property +new TextLayer({ data: { attributes: { maxWidth: new Int8Array() }, length: 4 } }); + +new ColumnLayer({ data: { attributes: { getElevation: new Int8Array(), getLineWidth: new Int8Array() }, length: 2 } }); +new GridCellLayer({ + // @ts-expect-error -- attributes contains a non-accessor property + data: { attributes: { getElevation: new Int8Array(), getLineWidth: new Int8Array() }, length: 2 }, +}); +new GridCellLayer({ + data: { + attributes: { getColor: new Int8Array(), getElevation: new Int8Array(), getPosition: new Int8Array() }, + length: 2, + }, +}); + +new BitmapLayer({ bounds: [2, 2, 2, 2], image: new HTMLCanvasElement() }).props.image.className; +// @ts-expect-error -- image is not HTMLElement +new BitmapLayer({ bounds: [2, 2, 2, 2], image: 'url' }).props.image.className; + +new ScatterplotLayer({ + data: 'url', + // @ts-expect-error -- x is unknown + getPosition(x) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + data: 'url', + getPosition(x: number) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + data: [1], + getPosition(x) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + data: [1], + // @ts-expect-error -- x is number + getPosition(x: unknown) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + // @ts-expect-error -- Promise is not LayerData + data: Promise.resolve(1), +}); + +new ScatterplotLayer({ + data: Promise.resolve([1]), + getPosition(x) { + return [x, 0]; + }, +}); + +function asyncData(t: T) { + return { + async *[Symbol.asyncIterator]() { + yield t; + }, + }; +} + +const asyncNumber = asyncData(1); +const asyncString = asyncData('data'); +new ScatterplotLayer({ + data: asyncNumber, + getPosition(x) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + data: asyncString, + getPosition(x) { + x + 'data'; + return [0, 0]; + }, +}); + +new ScatterplotLayer({ + data: { attributes: {}, length: 1 }, + // @ts-expect-error -- x is unknown + getPosition(x) { + return [x, 0]; + }, +}); + +new ScatterplotLayer({ + data: new Map(), + getPosition([, y]) { + return [0, y]; + }, +}); + +class ScatterLayer>> extends ScatterplotLayer< + D, + ScatterplotLayerProps +> { + renderLayers() { + const { data } = this.props; + + return [ + // when the data prop is externally constrained, you'll have to cast from `unknown` + new ScatterplotLayer({ + data, + // @ts-expect-error + getPosition(x) { + return [x, 0]; + }, + }), + + new ScatterplotLayer({ + data, + getPosition(x: number) { + return [x, 0]; + }, + }), + + new ScatterplotLayer({ + data: data as number[], + getPosition(x) { + return [x, 0]; + }, + }), + ]; + } +} diff --git a/test/deck.gl.ts b/test/deck.gl.ts index 80a1052..3d63721 100644 --- a/test/deck.gl.ts +++ b/test/deck.gl.ts @@ -1,22 +1,50 @@ /// -import { - AGGREGATION_OPERATION, - AmbientLight, - COORDINATE_SYSTEM, - Deck, - Layer, - LineLayer, - OrbitView, - PolygonLayer, - TextLayer, -} from 'deck.gl'; +import { Layer } from 'deck.gl'; interface P { foo: string; } -var layer1: Layer

; +var layer1: Layer; -var x = layer1.props.data as P[]; +var x = layer1.props.data; x[0].foo; + +new Layer({ ACustomPropStillWorks: true }); + +var y: Layer; +y.state.innerState; + +// @ts-expect-error -- data is not P[] +new Layer({ data: [2] }); + +new Layer({ data: [2] }); + +// @ts-expect-error -- missing attributes +new Layer({ data: { length: 4 } }); + +new Layer({ data: { attributes: {}, length: 4 } }); + +new Layer({ data: 'url' }); +new Layer({ data: Promise.resolve([1]) }).props.data.then(d => { + d[0] + 1; +}); +new Layer({ data: new Map().set('a', 1) }).props.data.get('a') + 1; +new Layer({ + data: { + async *[Symbol.asyncIterator]() { + yield 'data'; + }, + }, +}).props.data[Symbol.asyncIterator]; + +// @ts-expect-error -- data is not LayerData +new Layer({ data: new Date() }); + +new Layer({ data: ['d'] }, { extensions: [] }).props.data[0] + 'd'; + +declare const unknownArg: unknown; +new Layer({ + data: unknownArg as number[], +});