I am currently developing an Angular library that configures an OpenLayers map as an Angular component. The component is functioning properly, but I need to access classes and constants from a package imported by the library, specifically OpenLayers.
To work around this issue, I have also installed the same package within the Angular app. However, there seems to be some compatibility issues between the two packages, even though they are using the same version. It's difficult to articulate the problem in plain text, so I will provide some pseudo code to illustrate further.
In my Angular library, I have the following method:
import { Feature} from "ol";
....
public addFeature(feature: Feature) {
this.layer.getSource().addFeature(feature);
}
And in my Angular app, I have the following snippet:
import { Feature} from "ol";
public test() {
const feature = new Feature();
myLibService.addFeature(feature)
}
However, when I run this, I encounter the following error:
Argument of type 'Feature' is not assignable to parameter of type 'Feature'. Types of property 'on' are incompatible.
This issue can be resolved by changing the type of Feature
in the library function "addFeature" to type any
, which is something I would prefer to avoid. Creating a new Feature() inside my library works without any problems.
My Desired Outcome Ideally, I would like to import "Feature" from the "ol" package installed within my-lib directly into my Angular app. Is there a way to achieve this?
Etc:
import { Feature} from 'my-lib/node_modules/ol';
If you need further clarification or additional information, please feel free to ask. The provided code is purely pseudo-code, but conveys the same details as the actual implementation.
Thank you in advance!
I have attempted to install the "ol" (OpenLayers) package in both my Angular app and Angular library, with both using the same version.