From e8bf0bd080c071f73a8d309c16fdc4e5537097db Mon Sep 17 00:00:00 2001 From: Royston Shufflebotham Date: Thu, 10 Aug 2023 14:09:21 +0100 Subject: [PATCH] Fix typing of Map.getLayer() and Style.getLayer() (#2969) Fixes #2968 * Fix typing of Map.getLayer() and Style.getLayer() * Update CHANGELOG.md --------- Co-authored-by: Harel M --- CHANGELOG.md | 1 + src/style/style.ts | 2 +- src/ui/map.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2901bfec8e..468e1a3d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### 🐞 Bug fixes +- Correct declared return type of `Map.getLayer()` and `Style.getLayer()` to be `StyleLayer | undefined` to match the documentation. - _...Add new stuff here..._ ## 3.3.0 diff --git a/src/style/style.ts b/src/style/style.ts index 5777131458..9b7e4ef180 100644 --- a/src/style/style.ts +++ b/src/style/style.ts @@ -994,7 +994,7 @@ export class Style extends Evented { * @param id - id of the desired layer * @returns a layer, if one with the given `id` exists */ - getLayer(id: string): StyleLayer { + getLayer(id: string): StyleLayer | undefined { return this._layers[id]; } diff --git a/src/ui/map.ts b/src/ui/map.ts index 7220bd9811..d9e51276c1 100644 --- a/src/ui/map.ts +++ b/src/ui/map.ts @@ -2475,7 +2475,7 @@ export class Map extends Camera { * @see [Filter symbols by toggling a list](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers/) * @see [Filter symbols by text input](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers-by-input/) */ - getLayer(id: string): StyleLayer { + getLayer(id: string): StyleLayer | undefined { return this.style.getLayer(id); }