Skip to content

Commit

Permalink
feat(ol/feature): allow generics for feature.getProperties<T>()
Browse files Browse the repository at this point in the history
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 #14868
  • Loading branch information
d-koppenhagen committed Jan 21, 2024
1 parent d6975d4 commit 4355a97
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ol/render/Feature.js
Expand Up @@ -282,10 +282,12 @@ class RenderFeature {

/**
* Get the feature properties.
* @return {Object<string, *>} Feature properties.
* @template {Object<string, *>} T = An optional generic type of the requested feature properties
* @return {T} Feature properties.
* @api
*/
getProperties() {
// @ts-ignore (= this.properties_ as T)
return this.properties_;
}

Expand Down

0 comments on commit 4355a97

Please sign in to comment.