-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
VectorLayerOptions does not use the same generic type as VectorLayer #15837
Comments
@KyllianGautier The type of the Options has to include the source, because the options are used for several BaseVector layer subclasses. For the VectorLayer, the source type is determined and does not require generics for the source. Does this cause a real-life problem? |
@ahocevar Ok, I understand. I tryed to adapt, but I still have some very strange problems with the typing : |
Maybe you got some of the imports wrong? This works fine for me: import { FeatureLike as OLFeatureLike } from 'ol/Feature.js';
import { Options as OLBaseVectorLayerOptions } from 'ol/layer/BaseVector.js';
import OLVectorLayer from 'ol/layer/Vector.js';
import OLVectorSource from 'ol/source/Vector.js';
export const vectorLayer = <F extends OLFeatureLike>(options?: OLBaseVectorLayerOptions<OLVectorSource<F>>) => new OLVectorLayer<F>(options); |
@ahocevar Unfortunately, I have errors in typescript trying your solution: |
Thanks @KyllianGautier, you are right. In #15843 I made it so the options and the layer have the same generics again - both the |
@ahocevar thanks for this fix. I still have issue with typing in typescript :'( I'm sorry to disturbing you, but I don't find solution, and I don't know how to get the info to understand if I'm doing something wrong. You can test a simple example of the typing problem in Typescript: |
Yes, but you don't need to specify the
Correct, that's no longer the type signature.
That's also expected. There is no inheritance relationship between the allowed types of export const vectorLayer: OLVectorLayer<OLFeature> = new OLVectorLayer<OLFeature>(); |
@KyllianGautier You're still using the old type signature for the options. This should now be: import { Feature as OLFeature } from 'ol';
import OLVectorLayer, { Options as OLVectorLayerOptions } from 'ol/layer/Vector.js';
import OLVectorSource from 'ol/source/Vector.js';
const options: OLVectorLayerOptions<OLFeature> = {
source: new OLVectorSource<OLFeature>()
};
export const layer = new OLVectorLayer(options); |
@ahocevar Ok, problem solved, thanks for the support. I have an additional question about the Layer.getSource() method. How can we type the source returned by a VectorLayer ? If I use a Custer source for example, I instantiate a VectorLayer with this Cluster source, and i'm not able to use the Cluster source specific methods such as setDistance() or setMinDistance(): Other side effect, it seems that a VectorLayer with an other source than a Vector source is not assiciable with a Layer ? |
In #15869, the source type is added back as 2nd type parameter to vector and vectortile layers. |
Describe the bug
![image](https://private-user-images.githubusercontent.com/12836335/331521792-b5173a61-e1fb-4614-ba76-5c05c376eed3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3NzUxNzgsIm5iZiI6MTcxOTc3NDg3OCwicGF0aCI6Ii8xMjgzNjMzNS8zMzE1MjE3OTItYjUxNzNhNjEtZTFmYi00NjE0LWJhNzYtNWMwNWMzNzZlZWQzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDE5MTQzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThmYmU5ODY3NjY1ODU4NDZiNGM0YmJiYmZmZjEzNmFmMTk1NWFmOWY4ZWFiNTgzMDEzMzIyNWQxODMyZjU1YmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.us72q2PO6nonWJSOji13kQojzC8yLLE9OOVeFgu_Fhg)
![image](https://private-user-images.githubusercontent.com/12836335/331521894-f5cf77e0-4fde-4015-aa55-52e75a366b18.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3NzUxNzgsIm5iZiI6MTcxOTc3NDg3OCwicGF0aCI6Ii8xMjgzNjMzNS8zMzE1MjE4OTQtZjVjZjc3ZTAtNGZkZS00MDE1LWFhNTUtNTJlNzVhMzY2YjE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDE5MTQzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJlNWMxMWZjYzMwOGQxODU1ZjkzN2Q0ZWMxMTNlNzU5N2E4YmQ4NmY0Y2MxNjJkMDdmYjM2OWRjMWJhYjViMDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.x6vwAoOK_8yI2FclJm48eHR9sGe1hUIJgp-OOqKOL_Q)
VectorLayerOptions does not have the same generic type as VectorLayer
To Reproduce
Use a VectorLayer by instantiate it with a VectorLayerOptions:
(options?: OLVectorLayerOptions<OLFeatureLike>) => new OLVectorLayer<OLFeatureLike>(options)
See that the required types are not the same since the v9.2.1.
Before the v9.2.0, the types were both
VectorSource
.Expected behavior
We can instantiate a VectorLayer with an Option object that uses the same required generic type as VectorLayer.
Such as ClusterLayer and ClusterLayerOptions for example
The text was updated successfully, but these errors were encountered: