mapbox / mapbox/mapbox-gl-js

The source-layer field is optional, but why can't pass undefined

Open
#13,321 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

The source-layer field is optional, but when I pass the value undefined, the console gives an error: Error: layers.outline.source-layer: string expected, undefined found. I'm confused about this sign, but it doesn't seem to report an error in previous versions.
I provide an example of adding source-layer : undefined below.

**mapbox-gl-js version**: v3.7.0

**browser**: Chrome

### Link to Demonstration

https://jsbin.com/zepefoq/edit?html,output

### Expected Behavior
[layer.sourceLayer
[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer)

"source-layer"?: string,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked JSBin demonstration and the source-layer API documentation cited in the issue. Trace how v3.7.0 validates layer properties, then clarify and verify the expected behavior for an omitted versus explicitly undefined source-layer value; the issue names no source file or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.