Skip to content
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

maplibre v2.0.0 typings angular 13 #776

Closed
RobinKamps opened this issue Jan 14, 2022 · 24 comments
Closed

maplibre v2.0.0 typings angular 13 #776

RobinKamps opened this issue Jan 14, 2022 · 24 comments

Comments

@RobinKamps
Copy link

typings can not be found / are missing in 'node_modules/maplibre-gl/dist/maplibre-gl.d.ts'
e.g. TriangleIndexArray, LineIndexArray, LineStripIndexArray, VectorTileFeature, TransferableGridIndex, setSourceType, and a few more.

@HarelM
Copy link
Member

HarelM commented Jan 14, 2022

Types are now generated from the code. See the breaking changes in the release notes.
If there are other missing types, feel free to submit a PR.

@HarelM
Copy link
Member

HarelM commented Jan 15, 2022

I now see this too in my project.
As a workaround, you can set skipLibCheck: true in tsconfig.json file.
In order to truly fix this there's a need to follow the suggestions described here:
timocov/dts-bundle-generator#175 (comment)
Unfortunately, I couldn't find the time lately to do it.
These are basically simple instructions on how to fix the generated d.ts file.
It would help me tremendously if you could take a look at this as well...

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

I wrote a small example to reproduce these errors: https://github.com/wipfli/maplibre-typescript

This is a GitHub repo with a minimal TypeScript usage example. A GitHub workflow runs the TypeScript compiler, which fails with the following error message (see workflow run):

Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2021,39): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2021,60): error TS2304: Cannot find name 'LineIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2021,77): error TS2304: Cannot find name 'LineStripIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2371,27): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2371,48): error TS2304: Cannot find name 'LineIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2371,65): error TS2304: Cannot find name 'LineStripIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2746,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2749,22): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2750,33): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2751,18): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2752,18): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3062,8): error TS2304: Cannot find name 'TransferableGridIndex'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3063,10): error TS2304: Cannot find name 'TransferableGridIndex'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3069,16): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3073,18): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3075,16): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3097,75): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3104,17): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3210,16): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3365,91): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3389,59): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3489,21): error TS2304: Cannot find name 'CircleLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3491,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3499,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3555,63): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3566,21): error TS2304: Cannot find name 'FillLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3568,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3570,15): error TS2304: Cannot find name 'LineIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3579,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3633,63): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3644,21): error TS2304: Cannot find name 'FillExtrusionLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3646,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3658,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3703,63): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3757,21): error TS2304: Cannot find name 'LineLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3759,22): error TS2304: Cannot find name 'LineExtLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3761,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3769,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3860,63): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3965,21): error TS2304: Cannot find name 'SymbolLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3967,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3971,28): error TS2304: Cannot find name 'SymbolDynamicLayoutArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3973,22): error TS2304: Cannot find name 'SymbolOpacityArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3975,24): error TS2304: Cannot find name 'CollisionVertexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3987,14): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3987,35): error TS2304: Cannot find name 'LineIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3990,24): error TS2304: Cannot find name 'CollisionVertexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3995,23): error TS2304: Cannot find name 'TriangleIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(3995,44): error TS2304: Cannot find name 'LineIndexArray'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4056,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4275,11): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4326,41): error TS2304: Cannot find name 'VectorTileLayer'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4492,18): error TS2395: Individual declarations in merged declaration 'StyleLayer' must be all exported or all local.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4494,64): error TS2304: Cannot find name 'VectorTileFeature'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4496,24): error TS2395: Individual declarations in merged declaration 'StyleLayer' must be all exported or all local.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4709,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4712,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(6574,31): error TS2304: Cannot find name 'getSourceType'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(6575,31): error TS2304: Cannot find name 'setSourceType'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(6628,41): error TS2503: Cannot find namespace 'GeoJSON'.

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

It's even easier than that.
Just remove the --no-check from the post-ts-build.js file and you'll get the errors in the console.
I'm looking into it right now.
It will require some changes in order to make the tool "happy".
I'll open a branch to allow contribution.

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

Good idea.

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

See branch 776-fix-typescript-typings
The tool has issue with imports and exports that use as i.e. export something as somethingelse. I'll see if I can improve this in the branch...

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

Like these friends I guess...

StructArrayLayout2i4 as PosArray,
StructArrayLayout4i8 as RasterBoundsArray,
StructArrayLayout2i4 as CircleLayoutArray,
StructArrayLayout2i4 as FillLayoutArray,
StructArrayLayout2i4i12 as FillExtrusionLayoutArray,
StructArrayLayout2i4 as HeatmapLayoutArray,
StructArrayLayout2i4ub8 as LineLayoutArray,
StructArrayLayout2f8 as LineExtLayoutArray,
StructArrayLayout10ui20 as PatternLayoutArray,
StructArrayLayout4i4ui4i24 as SymbolLayoutArray,
StructArrayLayout3f12 as SymbolDynamicLayoutArray,
StructArrayLayout1ul4 as SymbolOpacityArray,
StructArrayLayout2i2i2i12 as CollisionBoxLayoutArray,
StructArrayLayout2f1f2i16 as CollisionCircleLayoutArray,
StructArrayLayout2ub2f12 as CollisionVertexArray,
StructArrayLayout3ui6 as QuadTriangleArray,
StructArrayLayout3ui6 as TriangleIndexArray,
StructArrayLayout2ui4 as LineIndexArray,
StructArrayLayout1ui2 as LineStripIndexArray

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

Yup.
Ok, I think I managed to follow most of the instructions in the tool thread linked above.
Below is the file generated from the tool.
Please let me know if this works, after that I can go back and improve the code.
mplibre-gl.d.txt
You can replace the d.ts file in the node_modules/maplibre-gl-js folder to see the effect of this...

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

We might need to publish the missing packages to definitely types project as the PR in mapbox are not being merged... :-(
i.e. this PR: mapbox/vector-tile-js#78

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

Beautiful @HarelM, so with the d.ts file you have above, the errors in the workflow run reduce to:

Error: app.ts(1,10): error TS2614: Module '"maplibre-gl"' has no exported member 'Map'. Did you mean to use 'import Map from "maplibre-gl"' instead?
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2772,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2777,18): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(2778,18): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4733,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(4736,13): error TS2503: Cannot find namespace 'GeoJSON'.
Error: node_modules/maplibre-gl/dist/maplibre-gl.d.ts(6652,41): error TS2503: Cannot find namespace 'GeoJSON'.

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

Or we create a fork of https://github.com/mapbox/vector-tile-js

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

ahh, wait, the tool didn't finished the run due to errors. let me try again...
How's this:
mplibre-gl.d.txt

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

GeoJSON error should be fixed by adding @types/geojson package I believe...?

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

I think you uploaded the same file again.

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

oh... yea... it has the same content.
Let me check this in my project as I think the file it OK now...

@wipfli
Copy link
Member

wipfli commented Jan 16, 2022

I can help with the failing unit tests. Can you open a pull request?

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

OK, so now the problem remains with the fact that grid-index and @mapbox/vector-tile packages are not typed and anyone that would like to use the types that are generated by this package will need to add their types which are not defined :-(

@HarelM
Copy link
Member

HarelM commented Jan 16, 2022

The branch is in this repo. Feel free to open a PR.

@wipfli wipfli mentioned this issue Jan 16, 2022
9 tasks
@HarelM
Copy link
Member

HarelM commented Jan 17, 2022

@RobinKamps can you check if the following file is good with angular 13?
mplibre-gl.d.txt
This is the final version of the file after all the changes in #787

@RobinKamps
Copy link
Author

It does work with Angular 13.
Thank you very much.

@HarelM HarelM closed this as completed in 9348083 Jan 18, 2022
@HarelM
Copy link
Member

HarelM commented Jan 18, 2022

@RobinKamps I've published 2.0.2 please let me know if it works for you.

@RobinKamps
Copy link
Author

2.0.2 is working fine.

@HarelM
Copy link
Member

HarelM commented Jan 22, 2022

I'm not sure what I did wrong but it seems that version 2.0.3 is not working anymore although I think the typings there are correct and even better than 2.0.2.
If anyone has a clue what could've gone wrong it would help me a lot as I have not clue what could've caused this.
I'm getting the following error when I try to use 2.0.3 with ngx-maplibre-gl:

./projects/ngx-maplibre-gl/src/lib/control/attribution-control.directive.ts:28:44-62 - Error: export 'AttributionControl' (imported as 'AttributionControl') was not found in 'maplibre-gl' (module has no exports)

What I basically did between 2.0.2 and 2.0.3 is that I now use the packages from mapbox along with typings that are from definitely typed.
The packages are @mapbox/vector-tile and @mapbox/point-geometry.
I could really use some help here...

@HarelM
Copy link
Member

HarelM commented Jan 22, 2022

Nevermind, I found the missing package.json file that for some reason was not published with 2.0.3... :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants