mapbox / mapbox/mapbox-gl-js

Unable to define a variable of type: `number` or `null`

Open
#8,703 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs discussion :speech_balloon:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I have a problem with the following expression:

```
"line-color": [
'let',
'aVsB',
[
'case',
['all', ['has', 'a'], ['has', 'b']],
['-', ['get', 'a'], ['get', 'b']],
null,
],
[
'case',
['!=', ['var', 'aVsB'], null],
[
'case',
['>', ['var', 'aVsB'], 0],
'blue',
'red',
],
"black",
],
],
```

I somehow need to indicate that the `aVsB` value is not valid. Is it possible to define a variable `aVsB` that can be either `number` or `null`? Then I'm going to compare it with `null` to display the necessary color.

Not working:
https://jsfiddle.net/NameFILIP/oLw1ysjm/34/

Workaround 1:
https://jsfiddle.net/NameFILIP/oLw1ysjm/31/

Workaround 2:
https://jsfiddle.net/NameFILIP/oLw1ysjm/36/

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 expression in the issue and compare the three linked jsfiddle reproductions, including both listed workarounds. Trace how the expression handles a variable assigned either a number or null, then define completion as consistent support for the requested comparison without breaking the demonstrated color expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.