mapbox / mapbox/mapbox-gl-js

Clarify type validation error message for == expression

Open
#6,387 1 comment 0 reactions 1 assignee View on GitHub

@domlet is already working on this.

Since Jul 9, 2021.

api :memo: docs :scroll: style-spec
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

@ChrisLoer points out that the documentation for `"=="` could be a bit confusing. The docs say:

> Equality is strictly typed: values of different types are always considered not equal

That is true for, e.g., `["==", ["get", "x"], 10]` applied to `{properties: {x: "10"}}`. However, it's _not_ true for an expression like `["==", "10", 10]`, which actually fails to typecheck with the message `Cannot compare string and number.` This error message appears to be in contradiction with the docs.

Let's clarify the message to something like:

> Cannot compare ${toString(lhs.type)} and ${toString(rhs.type)}: since these types are different, "==" would always return false. Consider using "to-${toString(lhs.type)}" or "to-${toString(rhs.type)}" in order to compare two values of the same 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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.