mapbox / mapbox/mapbox-gl-js

Flow complains on the filter definition inside of a layer

Open
#8,137 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation :mag: testing :100:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Flow complains on:

```
filter: [
'any',
['==', ['get', 'direction'], 'ba'],
['==', ['get', 'direction'], 'ab'],
],
```

with the error message:

```
Cannot return array literal because:
• Could not decide which case to select. Since case 3 [1] may work but if it doesn't case 9 [2] looks promising too.
To fix add a type annotation to array literal [3].
• Could not decide which case to select. Since case 3 [1] may work but if it doesn't case 9 [2] looks promising too.
To fix add a type annotation to array literal [4].

src/selectors/get-map-style.js
[3] 262│ ['==', ['get', 'direction'], 'ba'],
[4] 263│ ['==', ['get', 'direction'], 'ab'],
:
289│ ];
290│ }
291│
292│ return [sources, layers];
293│ }
294│

../../node_modules/@mapbox/mapbox-gl-style-spec/types.js
[1] 12│ | ['==', string, string | number | boolean]
:
[2] 18│ | Array; // Can't type in, !in, all, any, none -- https://github.com/facebook/flow/issues/2443

Found 2 errors
```

Looks like the [`==` filter definition](https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/types.js#L12) is missing the array type

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

Inspect ../../node_modules/@mapbox/mapbox-gl-style-spec/types.js around lines 12 and 18, then review the failing filter literals in src/selectors/get-map-style.js. Run Flow to reproduce the two errors and verify the filter definition accepts the reported array form without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.