Fix typing of Map.getLayer() and Style.getLayer() #2969
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Launch Checklist
Fixes #2968
getSource
in December 2021.Include before/after visuals or gifs if this PR includes visual changes.N/AWrite tests for all new functionality.This includes typing changes only.Document any changes to public APIs.This change actually makes the advertised API match the documented APIs.Post benchmark scores.This does not affect generated code at all, so can't affect performance.CHANGELOG.md
under the## main
section.Changes
This PR changes the return types of:
Map.getLayer()
from returningStyleLayer
toStyleLayer | undefined
Style.getLayer()
from returningStyleLayer
toStyleLayer | undefined
Those declared return types are changing to match the existing documented behaviour, and brings them in line with the existing similar
Map.getSource()
andStyle.getSource()
methods.Notes
Yes and no. It's making the TypeScript-advertised type match the already-documented and implemented behaviour. It is possible that this could cause existing code to fail to compile if it's calling
getLayer()
and is compiled with a strict type-checking mode that will flag up that the return type is not being checked forundefined
.See PR #724 for earlier work which made the same change to the
getSource()
methods.