-
-
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
TS allow generics for getProperties()
#14868
Labels
Comments
d-koppenhagen
added a commit
to d-koppenhagen/openlayers
that referenced
this issue
Jan 21, 2024
with this change it's possible to pass a generic type `T` when calling `feature.getProperties<T>()` and using with TypeScript. ``` // before: const stop = feature?.getProperties() as Stop const stop = feature?.getProperties<Stop>() console.log(typeof stop) // "Stop" ``` closes openlayers#14868
d-koppenhagen
added a commit
to d-koppenhagen/openlayers
that referenced
this issue
Jan 21, 2024
with this change it's possible to infer the type `T` of passed properties when calling `feature.getProperties()` and using with TypeScript. ```ts type Vehicle = { type: 'Car' | 'Bike' | 'Truck', color: string } const car: Vehicle = { type: 'Car', color: 'Red' } // Before the change const feature = new RenderFeature(car); const properties = feature.getProperties(); // properties inferred as Object<string, *> // After the change const feature = new RenderFeature(car); const properties = feature.getProperties(); // properties inferred as Vehicle ``` closes openlayers#14868
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
As a user of Openlayers with TypeScript, I want to be able to receive
feature
properties by passing a type as generic.This allows to explicitly set the type of feature properties for further processing.
Describe the solution you'd like
Current Behavior:
Solution i'd like:
The text was updated successfully, but these errors were encountered: