@@ -18,7 +18,9 @@ import type {
1818 LayerSpecification ,
1919 FilterSpecification ,
2020 VisibilitySpecification ,
21- VisibilityExpression
21+ VisibilityExpression ,
22+ AllPaintProperties ,
23+ AllLayoutProperties ,
2224} from '@maplibre/maplibre-gl-style-spec' ;
2325import type { TransitionParameters , PropertyValue } from './properties' ;
2426import { type EvaluationParameters } from './evaluation_parameters' ;
@@ -32,6 +34,8 @@ import {type mat4} from 'gl-matrix';
3234import type { UnwrappedTileID } from '../tile/tile_id' ;
3335import type { VectorTileFeatureLike } from '@maplibre/vt-pbf' ;
3436
37+ type PaintPropertyEntry = { [ K in keyof AllPaintProperties ] : { name : K ; value : AllPaintProperties [ K ] } } [ keyof AllPaintProperties ] ;
38+
3539export type QueryIntersectsFeatureParams = {
3640 /**
3741 * The geometry to check intersection with.
@@ -153,10 +157,10 @@ export abstract class StyleLayer extends Evented {
153157 this . _transitionablePaint = new Transitionable ( properties . paint , globalState ) ;
154158
155159 for ( const property in layer . paint ) {
156- this . setPaintProperty ( property , layer . paint [ property ] , { validate : false } ) ;
160+ this . setPaintProperty ( property as keyof AllPaintProperties , layer . paint [ property as keyof typeof layer . paint ] , { validate : false } ) ;
157161 }
158162 for ( const property in layer . layout ) {
159- this . setLayoutProperty ( property , layer . layout [ property ] , { validate : false } ) ;
163+ this . setLayoutProperty ( property as keyof AllLayoutProperties , layer . layout [ property as keyof typeof layer . layout ] , { validate : false } ) ;
160164 }
161165
162166 this . _transitioningPaint = this . _transitionablePaint . untransitioned ( ) ;
@@ -174,9 +178,9 @@ export abstract class StyleLayer extends Evented {
174178 return this . _crossfadeParameters ;
175179 }
176180
177- getLayoutProperty ( name : string ) {
181+ getLayoutProperty < K extends keyof AllLayoutProperties > ( name : K ) : AllLayoutProperties [ K ] {
178182 if ( name === 'visibility' ) {
179- return this . visibility ;
183+ return this . visibility as AllLayoutProperties [ K ] ;
180184 }
181185 if ( this . _transitionablePaint ?. hasProperty ( name ) ) {
182186 throw new Error ( name + ERROR_PAINT_NOT_LAYOUT ) ;
@@ -221,16 +225,16 @@ export abstract class StyleLayer extends Evented {
221225 * This is used to determine if layer needs to be repainted when global state property changes.
222226 *
223227 */
224- getPaintAffectingGlobalStateRefs ( ) : globalThis . Map < string , Array < { name : string ; value : any } > > {
225- const globalStateRefs = new globalThis . Map < string , Array < { name : string ; value : any } > > ( ) ;
228+ getPaintAffectingGlobalStateRefs ( ) : globalThis . Map < string , Array < PaintPropertyEntry > > {
229+ const globalStateRefs = new globalThis . Map < string , Array < PaintPropertyEntry > > ( ) ;
226230
227231 if ( this . _transitionablePaint ) {
228232 for ( const propertyName in this . _transitionablePaint . _values ) {
229233 const value = this . _transitionablePaint . _values [ propertyName ] . value ;
230234
231235 for ( const globalStateRef of value . getGlobalStateRefs ( ) ) {
232236 const properties = globalStateRefs . get ( globalStateRef ) ?? [ ] ;
233- properties . push ( { name : propertyName , value : value . value } ) ;
237+ properties . push ( { name : propertyName as keyof AllPaintProperties , value : value . value } as PaintPropertyEntry ) ;
234238 globalStateRefs . set ( globalStateRef , properties ) ;
235239 }
236240 }
@@ -247,10 +251,10 @@ export abstract class StyleLayer extends Evented {
247251 return this . _visibilityExpression . getGlobalStateRefs ( ) ;
248252 }
249253
250- setLayoutProperty ( name : string , value : any , options : StyleSetterOptions = { } ) {
254+ setLayoutProperty < K extends keyof AllLayoutProperties > ( name : K , value : AllLayoutProperties [ K ] , options : StyleSetterOptions = { } ) {
251255 if ( name === 'visibility' ) {
252- this . visibility = value ;
253- this . _visibilityExpression . setValue ( value ) ;
256+ this . visibility = value as VisibilitySpecification ;
257+ this . _visibilityExpression . setValue ( value as VisibilitySpecification ) ;
254258 this . recalculateVisibility ( ) ;
255259 return ;
256260 }
@@ -265,23 +269,23 @@ export abstract class StyleLayer extends Evented {
265269 this . _unevaluatedLayout . setValue ( name , value ) ;
266270 }
267271
268- getPaintProperty ( name : string ) {
272+ getPaintProperty < K extends keyof AllPaintProperties > ( name : K ) : AllPaintProperties [ K ] {
269273 if ( name . endsWith ( TRANSITION_SUFFIX ) ) {
270274 const baseName = name . slice ( 0 , - TRANSITION_SUFFIX . length ) ;
271275 if ( baseName === 'visibility' || this . _unevaluatedLayout ?. hasProperty ( baseName ) ) {
272276 throw new Error ( name + ERROR_LAYOUT_NOT_PAINT ) ;
273277 }
274- return this . _transitionablePaint . getTransition ( baseName ) ;
278+ return this . _transitionablePaint . getTransition ( baseName ) as AllPaintProperties [ K ] ;
275279 } else {
276- if ( name === 'visibility' || this . _unevaluatedLayout ?. hasProperty ( name ) ) {
280+ if ( this . _unevaluatedLayout ?. hasProperty ( name ) ) {
277281 throw new Error ( name + ERROR_LAYOUT_NOT_PAINT ) ;
278282 }
279- return this . _transitionablePaint . getValue ( name ) ;
283+ return this . _transitionablePaint . getValue ( name ) as AllPaintProperties [ K ] ;
280284 }
281285 }
282286
283- setPaintProperty ( name : string , value : unknown , options : StyleSetterOptions = { } ) {
284- if ( name === 'visibility' || ( this . _unevaluatedLayout ?. hasProperty ( name ) ) ) {
287+ setPaintProperty < K extends keyof AllPaintProperties > ( name : K , value : AllPaintProperties [ K ] , options : StyleSetterOptions = { } ) {
288+ if ( this . _unevaluatedLayout ?. hasProperty ( name ) ) {
285289 this . fire ( new ErrorEvent ( new Error ( name + ERROR_LAYOUT_NOT_PAINT ) ) ) ;
286290 return false ;
287291 }
0 commit comments