Skip to content

Commit e22207b

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Allow literal value types for expression properties in Style Spec types (internal-8826)
GitOrigin-RevId: cf0e61cd7d46e1360a15af8cbe8ab480d1fb4001
1 parent d3a9e78 commit e22207b

3 files changed

Lines changed: 22 additions & 25 deletions

File tree

build/generate-typed-style-spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ function tsType(property, overrideFn?: (any) => string) {
7979
return `PropertyValueSpecification<${baseType}>`;
8080
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8181
} else if (property.expression) {
82-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
83-
if (property.type === 'enum') return `${baseType} | ExpressionSpecification`;
84-
return `ExpressionSpecification`;
82+
return `${baseType} | ExpressionSpecification`;
8583
} else {
8684
return baseType;
8785
}

src/style-spec/types.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export type CameraSpecification = {
315315
};
316316

317317
export type ColorThemeSpecification = {
318-
"data"?: ExpressionSpecification
318+
"data"?: string | ExpressionSpecification
319319
};
320320

321321
export type ProjectionSpecification = {
@@ -359,7 +359,7 @@ export type SchemaSpecification = {
359359
};
360360

361361
export type OptionSpecification = {
362-
"default": ExpressionSpecification,
362+
"default": unknown | ExpressionSpecification,
363363
"type"?: "string" | "number" | "boolean" | "color",
364364
"array"?: boolean,
365365
"minValue"?: number,
@@ -710,7 +710,7 @@ export type LineLayerSpecification = {
710710
/**
711711
* @experimental This property is experimental and subject to change in future versions.
712712
*/
713-
"line-cross-slope"?: ExpressionSpecification,
713+
"line-cross-slope"?: number | ExpressionSpecification,
714714
"visibility"?: "visible" | "none" | ExpressionSpecification,
715715
/**
716716
* @experimental This property is experimental and subject to change in future versions.
@@ -737,7 +737,7 @@ export type LineLayerSpecification = {
737737
"line-dasharray"?: DataDrivenPropertyValueSpecification<Array<number>>,
738738
"line-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
739739
"line-pattern-cross-fade"?: PropertyValueSpecification<number>,
740-
"line-gradient"?: ExpressionSpecification,
740+
"line-gradient"?: ColorSpecification | ExpressionSpecification,
741741
"line-gradient-use-theme"?: PropertyValueSpecification<string>,
742742
"line-trim-offset"?: [number, number],
743743
/**
@@ -805,7 +805,7 @@ export type SymbolLayerSpecification = {
805805
/**
806806
* @experimental This property is experimental and subject to change in future versions.
807807
*/
808-
"icon-size-scale-range"?: ExpressionSpecification,
808+
"icon-size-scale-range"?: [number, number] | ExpressionSpecification,
809809
"icon-text-fit"?: DataDrivenPropertyValueSpecification<"none" | "width" | "height" | "both">,
810810
"icon-text-fit-padding"?: DataDrivenPropertyValueSpecification<[number, number, number, number]>,
811811
"icon-image"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
@@ -824,7 +824,7 @@ export type SymbolLayerSpecification = {
824824
/**
825825
* @experimental This property is experimental and subject to change in future versions.
826826
*/
827-
"text-size-scale-range"?: ExpressionSpecification,
827+
"text-size-scale-range"?: [number, number] | ExpressionSpecification,
828828
"text-max-width"?: DataDrivenPropertyValueSpecification<number>,
829829
"text-line-height"?: DataDrivenPropertyValueSpecification<number>,
830830
"text-letter-spacing"?: DataDrivenPropertyValueSpecification<number>,
@@ -884,10 +884,10 @@ export type SymbolLayerSpecification = {
884884
"text-translate"?: PropertyValueSpecification<[number, number]>,
885885
"text-translate-transition"?: TransitionSpecification,
886886
"text-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
887-
"icon-color-saturation"?: ExpressionSpecification,
888-
"icon-color-contrast"?: ExpressionSpecification,
889-
"icon-color-brightness-min"?: ExpressionSpecification,
890-
"icon-color-brightness-max"?: ExpressionSpecification,
887+
"icon-color-saturation"?: number | ExpressionSpecification,
888+
"icon-color-contrast"?: number | ExpressionSpecification,
889+
"icon-color-brightness-min"?: number | ExpressionSpecification,
890+
"icon-color-brightness-max"?: number | ExpressionSpecification,
891891
/**
892892
* @experimental This property is experimental and subject to change in future versions.
893893
*/
@@ -988,7 +988,7 @@ export type HeatmapLayerSpecification = {
988988
"heatmap-weight"?: DataDrivenPropertyValueSpecification<number>,
989989
"heatmap-intensity"?: PropertyValueSpecification<number>,
990990
"heatmap-intensity-transition"?: TransitionSpecification,
991-
"heatmap-color"?: ExpressionSpecification,
991+
"heatmap-color"?: ColorSpecification | ExpressionSpecification,
992992
"heatmap-color-use-theme"?: PropertyValueSpecification<string>,
993993
"heatmap-opacity"?: PropertyValueSpecification<number>,
994994
"heatmap-opacity-transition"?: TransitionSpecification
@@ -1024,7 +1024,7 @@ export type FillExtrusionLayerSpecification = {
10241024
/**
10251025
* @experimental This property is experimental and subject to change in future versions.
10261026
*/
1027-
"fill-extrusion-edge-radius"?: ExpressionSpecification
1027+
"fill-extrusion-edge-radius"?: number | ExpressionSpecification
10281028
},
10291029
"paint"?: {
10301030
"fill-extrusion-opacity"?: PropertyValueSpecification<number>,
@@ -1104,7 +1104,7 @@ export type FillExtrusionLayerSpecification = {
11041104
* @experimental This property is experimental and subject to change in future versions.
11051105
*/
11061106
"fill-extrusion-rounded-roof"?: PropertyValueSpecification<boolean>,
1107-
"fill-extrusion-cutoff-fade-range"?: ExpressionSpecification,
1107+
"fill-extrusion-cutoff-fade-range"?: number | ExpressionSpecification,
11081108
"fill-extrusion-emissive-strength"?: DataDrivenPropertyValueSpecification<number>,
11091109
"fill-extrusion-emissive-strength-transition"?: TransitionSpecification,
11101110
/**
@@ -1161,7 +1161,7 @@ export type BuildingLayerSpecification = {
11611161
"paint"?: {
11621162
"building-opacity"?: PropertyValueSpecification<number>,
11631163
"building-opacity-transition"?: TransitionSpecification,
1164-
"building-ambient-occlusion-intensity"?: ExpressionSpecification,
1164+
"building-ambient-occlusion-intensity"?: number | ExpressionSpecification,
11651165
"building-ambient-occlusion-intensity-transition"?: TransitionSpecification,
11661166
"building-ambient-occlusion-ground-intensity"?: PropertyValueSpecification<number>,
11671167
"building-ambient-occlusion-ground-intensity-transition"?: TransitionSpecification,
@@ -1176,7 +1176,7 @@ export type BuildingLayerSpecification = {
11761176
"building-color-use-theme"?: PropertyValueSpecification<string>,
11771177
"building-emissive-strength"?: DataDrivenPropertyValueSpecification<number>,
11781178
"building-facade-emissive-chance"?: PropertyValueSpecification<number>,
1179-
"building-cutoff-fade-range"?: ExpressionSpecification,
1179+
"building-cutoff-fade-range"?: number | ExpressionSpecification,
11801180
"building-flood-light-color"?: PropertyValueSpecification<ColorSpecification>,
11811181
"building-flood-light-color-transition"?: TransitionSpecification,
11821182
"building-flood-light-color-use-theme"?: PropertyValueSpecification<string>,
@@ -1217,7 +1217,7 @@ export type RasterLayerSpecification = {
12171217
"paint"?: {
12181218
"raster-opacity"?: PropertyValueSpecification<number>,
12191219
"raster-opacity-transition"?: TransitionSpecification,
1220-
"raster-color"?: ExpressionSpecification,
1220+
"raster-color"?: ColorSpecification | ExpressionSpecification,
12211221
"raster-color-use-theme"?: PropertyValueSpecification<string>,
12221222
"raster-color-mix"?: PropertyValueSpecification<[number, number, number, number]>,
12231223
"raster-color-mix-transition"?: TransitionSpecification,
@@ -1279,7 +1279,7 @@ export type RasterParticleLayerSpecification = {
12791279
"paint"?: {
12801280
"raster-particle-array-band"?: string,
12811281
"raster-particle-count"?: number,
1282-
"raster-particle-color"?: ExpressionSpecification,
1282+
"raster-particle-color"?: ColorSpecification | ExpressionSpecification,
12831283
"raster-particle-color-use-theme"?: PropertyValueSpecification<string>,
12841284
"raster-particle-max-speed"?: number,
12851285
"raster-particle-speed-factor"?: PropertyValueSpecification<number>,
@@ -1395,7 +1395,7 @@ export type ModelLayerSpecification = {
13951395
"model-roughness-transition"?: TransitionSpecification,
13961396
"model-height-based-emissive-strength-multiplier"?: DataDrivenPropertyValueSpecification<[number, number, number, number, number]>,
13971397
"model-height-based-emissive-strength-multiplier-transition"?: TransitionSpecification,
1398-
"model-cutoff-fade-range"?: ExpressionSpecification,
1398+
"model-cutoff-fade-range"?: number | ExpressionSpecification,
13991399
"model-front-cutoff"?: PropertyValueSpecification<[number, number, number]>,
14001400
"model-elevation-reference"?: "sea" | "ground" | "hd-road-markup" | ExpressionSpecification
14011401
},
@@ -1477,7 +1477,7 @@ export type SkyLayerSpecification = {
14771477
"sky-atmosphere-sun-intensity"?: number,
14781478
"sky-gradient-center"?: PropertyValueSpecification<[number, number]>,
14791479
"sky-gradient-radius"?: PropertyValueSpecification<number>,
1480-
"sky-gradient"?: ExpressionSpecification,
1480+
"sky-gradient"?: ColorSpecification | ExpressionSpecification,
14811481
"sky-gradient-use-theme"?: PropertyValueSpecification<string>,
14821482
"sky-atmosphere-halo-color"?: ColorSpecification,
14831483
"sky-atmosphere-halo-color-use-theme"?: PropertyValueSpecification<string>,
@@ -1531,8 +1531,8 @@ export type ClipLayerSpecification = {
15311531
"maxzoom"?: number,
15321532
"filter"?: FilterSpecification,
15331533
"layout"?: {
1534-
"clip-layer-types"?: ExpressionSpecification,
1535-
"clip-layer-scope"?: ExpressionSpecification
1534+
"clip-layer-types"?: Array<"model" | "symbol"> | ExpressionSpecification,
1535+
"clip-layer-scope"?: Array<string> | ExpressionSpecification
15361536
},
15371537
/**
15381538
* @experimental This property is experimental and subject to change in future versions.

test/build/typings/types__mapbox-gl.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,6 @@ const skyPaint: NonNullable<mapboxgl.SkyPaint> = {
19021902
"sky-atmosphere-sun": eitherType([0], expression),
19031903
// @ts-expect-error - incompatible
19041904
"sky-atmosphere-sun-intensity": eitherType(0, expression),
1905-
// @ts-expect-error - incompatible
19061905
"sky-gradient": eitherType("#000", expression),
19071906
// @ts-expect-error - incompatible
19081907
"sky-gradient-center": eitherType([0], expression),

0 commit comments

Comments
 (0)