-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating from @types/mapbox-gl
to first-class TypeScript typings
#13203
Comments
@types/mapbox-gl
to the Mapbox GL JS types
@types/mapbox-gl
to the Mapbox GL JS types@types/mapbox-gl
to first-class TypeScript typings
Some learnings from my migration:
In the code below I'm getting a TS error for the
mapRef.current?.addLayer({
id: 'unclustered-point',
type: 'circle',
source: SOURCE_ID,
filter: ['!', ['has', 'point_count']],
paint: {
'circle-radius': {
base: 1.5, // <-- TS error here
stops: [
[4, 8],
[10, 16],
],
},
'circle-color': circleColor,
},
}); |
Hi @slavanga, Thanks for sharing your learnings! The error in your case is caused by using the deprecated zoom function syntax. While the older syntax is still supported, the type we use for data-driven expressions doesn’t include it. You can refer to this comparison as an example of migrating to the newer syntax:
In your case, it should be: 'circle-radius': [
'interpolate',
['exponential', 1.5],
['zoom'],
4, 8,
10, 16
] I understand that it may not be convenient, so in the stable release, we could extend the type we provide to include the older syntax, making the migration process smoother for everyone. |
@stepankuzmin Got it! Thank you for the detailed explanation. I actually think the new syntax is more clear. |
Hi, I'm starting the migration to v3.5 and so far all deprecated types are easy to update, except one, which I'm having problems with:
|
I started the migration today and it went mostly well, but I got one small issue: At one point we use Similarly |
Some more feedback
|
For Angular applications that use the ever-stagnating |
Some types are not exported, such as Marker Options, ControlPosition, EasingOptions, StyleImageInterface |
Argument of type 'ScaleControl' is not assignable to parameter of type 'IControl'. Types of property '_setLanguage' are incompatible. |
Thanks for the feedback. We appreciate your patience while we enhance the developer experience. We are actively working on improving TypeScript support, and the upcoming patch release will address some of the issues highlighted here. Stay tuned for updates. |
three things (and some of this could be
seems like typescript should be able to tell which event string goes to which event type, so having that set up would be nice
a little annoying that the target is
when i change it to the string i'll add |
new mapboxgl.Popup().on('close', () => {}); Argument of type '"close"' is not assignable to parameter of type 'MapEvent'. |
I get this error in node_modules\mapbox-gl\dist\mapbox-gl.d.ts
ImageSource.titleId: CanonicalTileID | null | undefined; |
The types in 3.5.1 are disallowing passing a number as the map.fitBounds(bounds, {
maxZoom: 12,
padding: 80,
// ~~~~~~~
// Type 'number' is not assignable to type 'PaddingOptions'. ts(2322)
// (property) padding?: PaddingOptions | undefined
}); According to the API reference this should still be supported (and my brief skim of the code confirms this) |
I encountered a few types that are used for arguments on public methods but are not exported:
|
Hi everyone. We've just published the GL JS v3.5.2 patch release, which includes TypeScript API improvements such as strongly typed Map event listeners, improved type narrowing, and explicit exports for some previously missed types. Please try out the new version and let us know how it works for you. Thanks again for the feedback. I'll keep this issue open for any new findings. |
I believe type |
@stepankuzmin A couple of remaining type issues in
|
map.addLayer({
'id': 'tower',
'type': 'model',
'source': 'model',
'layout': {
'model-id': ['get', 'model-uri']
},
'paint': {
'model-cast-shadows': true,
}
}); Type 'boolean' is not assignable to type '[string, ...any[]]'.ts(2322) |
map.addLayer({
'id': 'tower',
'type': 'model',
'source': 'model',
'layout': {
'model-id': ['get', 'model-uri']
},
'paint': {
'model-rotation': [0.0, 0.0, ['get', 'rotate']],
}
}); Type '[number, number, string[]]' is not assignable to type 'DataDrivenPropertyValueSpecification<[number, number, number]> | undefined'. |
map.setLights([
{
"id": "directional",
"type": "directional",
"properties": {
"cast-shadows": true,
}
}
]) Type 'boolean' is not assignable to type '[string, ...any[]]'.ts(2322) |
Spotted a small little mistake when updating from 3.4.0 to 3.6.0 and using the mapbox-gl types. Apart from that seems like the Map type references to itself or something because as soon as I try to pass it as an argument through one of my functions; |
Hello, It's look like a mistake is made for the function My code:
I got the next error: I check the documentation and we can use an object and it's required when the type isn't |
This is pretty annoying, any chance to fix it? |
MapboxGL has moved to first-class TypeScript support, the community tyings are now outdated. (mapbox/mapbox-gl-js#13203)
Hello I just tried the migration from v2.3 to v3.5 and I have these errors and my markers doesn't want to appear The error is giving me this link : |
Migrating from
@types/mapbox-gl
to first-class TypeScript typingsThe GL JS v3.5.0 release marks a significant transition for GL JS, moving from Flow to TypeScript. While we have maintained backward compatibility where possible, the community typings
@types/mapbox-gl
are not fully compatible with the new first-class typings. Users relying on the community typings may experience breaking changes. This guide will help you migrate to the new first-class typings and resolve common issues.Please feel free to comment on this issue if you encounter difficulties during migration. Share your experiences and suggestions to support one another.
Updating GL JS
Install the latest version of GL JS and remove the
@types/mapbox-gl
dependency.Run the TypeScript compiler (
tsc
) to check for the errors.Common issues
The migration should be straightforward since there's no need to change how you interact with the API; only the types have changed. However, you may encounter some common issues.
Dangling
@types/mapbox-gl
Ensure you're using the latest version of GL JS and have removed the
@types/mapbox-gl
dependency.Deprecated Features
Community typings provided features deprecated since v1 and v2, such as the
optimizeForTerrain
map option,tiledata
andtiledataloading
events, zoom and property functions, certain exports like themapboxgl.Control
. Please refer to the compatibility test suite intest/build/typings/compatibility-test.ts
, used to test first-class typings compatibility with the community typings. Tests incompatible withmapbox-gl
typings are marked with@ts-expect-error - incompatible
.Naming Conventions
Community typings' naming convention slightly differs from those provided with GL JS:
*Specification
(e.g.,StyleSpecification
,LayerSpecification
), whereas in@types/mapbox-gl
, there's no suffix (e.g.,Style
,AnyLayer
).FillLayout
andFillPaint
. Instead, use TypeScript Indexed Access TypeFillLayerSpecification['layout']
for layout properties andFillLayerSpecification['paint']
for paint properties.Impl
suffix. For example,VectorSourceImpl
is exported asVectorSource
.Any*
types follow the same pattern:AnySourceData
becomesSourceSpecification
in GL JS,AnyLayer
becomesLayerSpecification
, andAnySourceImpl
becomesSource
.Note: We've created aliases where possible (e.g.,
MapboxOptions
as an alias toMapOptions
) and marked these aliases as@deprecated
in the first-class typings (this might be visible in your editor, e.g., with strikethrough style in VSCode IntelliSense). However, due to potential collisions, we couldn't create aliases for all cases. For example, we couldn't aliasSource
toSourceSpecification
because GL JS already exportsSource
(same asAnySourceImpl
in community typings). We recommend using the new naming convention, but aliases will help you migrate smoothly. Please note that these deprecated types will be removed in future releases.The text was updated successfully, but these errors were encountered: