-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Gloabl Map
collides with our Map
object, I think...
#287
Comments
Might be related to #286. The handling of collisions with "global" types was added in 9.2 so hopefully downgrading to 9.1 should help as a workaround. |
It is not a bug in the tool, this line in the build scripts is the issue https://github.com/maplibre/maplibre-gl-js/blob/b364c529d63d39012e28e7e1a4882e1c413d2a7d/build/generate-typings.ts#L14 (basically adding types = types.replace(/declare class/g, 'export declare class'); The tool now can rename items in the generated bundle to avoid collisions, including collisions with global types (from |
Well, I kinda do export them... So one should be able to: import maplibregl from 'maplibre-gl';
const map = new maplibregl.Map(...); but also: import {Map} from 'maplibre-gl';
const map = new Map(...); Both are valid and should work, I just don't know how to make the tool understand that. I'm struggling to find a good solution for both problems. Any help would be appreciated. |
@HarelM, I wrote my thought here #286 (comment) But you can try to think of it from another perspective. Let’s imagine you didn’t have this bundle. So it means your index.ts file https://github.com/maplibre/maplibre-gl-js/blob/b364c529d63d39012e28e7e1a4882e1c413d2a7d/src/index.ts#L271 exports the only default variable If you look at your
How to achieve this without the bundle? Just export everything before exporting the default variable in the
So the idea is if you write working code without the bundle, the bundle makes the compatible code and everything will work without any additional manipulations. |
:-) rollup complains that you are exporting in two different ways. export {
type Map
} But then I need to export things that are basically already exported and this creates duplication in maintenance... |
@HarelM Exporting types is not the same as exporting classes. import { Map } from 'maplibre-gl';
const map = new Map(); // 'Map' cannot be used as a value because it was exported using 'export type'. You have to export it as it if you want to reach the same behaviour. Or you have to drop named import support |
The type itself exists in the |
@HarelM I see, I showed you an error TS throws when using wrong defined d.ts file. So it does not affect the JS result, it’s only the TS error. But it’s not what you’ll expect. What I’m trying to say is your code should be valid before applying any bundle. Currently, it exports the only default class, but you are expecting it exporting named variables as well. To reach this you need to write a valid |
I agree with what you are saying, I just don't know how to solve this properly, the export type is just a hack I guess... |
@HarelM I’d suggest you to drop default export in the future releases and figure out the issue with rollup. import MapLibreGL from './index'; // import default class
// export all named classes
export {Map} from './ui/map';
export {NavigationControl} from './ui/control/navigation_control';
export default MapLibreGL; // re-export default class |
Currently, I've solved it by exporting the type of all the missing classes as can be seen here: |
I'm struggling to get it right. I'm not sure what I should do honestly. |
Yeah I see your confusion, but to be honest
@HarelM in case if you can do a breaking change, what you can't sacrifice 100%? Its hard to suggest anything if you need to keep somewhat "weird" old-days style of exporting API in JS. I can understand the reasoning behind why it was like that years ago, but now it feels a bit out. I'm ready to help you with this journey from my experience and point of view, we can have some dialog either here or you can create another discussion/issue in your repo or so - as you wish. I agree with what @Atrue was saying above, and I sympathize the suggestion of getting rid of default export as it cases all sorts of problems (or can cause them) as very first step. Secondly, I'd remove |
Re this - can you provide examples of what use-cases you'd absolutely need to keep? I'm not familiar with your library so to provide any good advice I need to understand its usage more.
I see your point and I 100% agree that a library author shouldn't generate unnecessary changes that break things up and make DX worse for no reason, but this is kinda slippery slope situation - instead of making a breaking change at "early stages" and re-design the API surface you can ended up keeping "old way of designing the API because users used to use it this way". It is not necessary bad tho, but it might make your life worse (or your users).
Again, I'm not familiar with the library and its internals, but from my experience while globals might be useful, at the end of the day they cause so much pain - e.g. if you need to maintain several different instances in your application your global values might be different between them and it might be helpful to scope them to an instance; also there is a chance of introducing memory leaks if you accidentally store some objects that shouldn't be there. It might not be your case of course, and these changes are huge.
To this, it seems (based on what I read in this thread) that what you wrote in |
I opened the following discussion: |
Bug report
Input code
See the difference of the
Map
object between version 4.0.0-pre.2 and 4.0.0-pre.3 of our library here:https://unpkg.com/[email protected]/dist/maplibre-gl.d.ts
https://unpkg.com/[email protected]/dist/maplibre-gl.d.ts
Expected output
Map
object should be exported asMap
and not asMap$1
Actual output
Map
is exported asMap$1
.This is basically an unintended break as the object that should be exported is
Map
and notMap$1
Additional context
I don't think there're a lot of changes to this library beside the upgrade version version 8.1.2 to 9.2.1, so I tend to think this is the root cause of this.
It seems like this should have been solved by a bug fix in version 9.2 according to the changelog, but I don't think it solved this specific case.
Let me know if you need more info in order to reproduce this issue.
The repo can be found here:
https://github.com/maplibre/maplibre-gl-js
Thanks for all the hard work put into this library! Truly appreciated!
The text was updated successfully, but these errors were encountered: