Skip to content

Fix InlayHint.is throwing on undefined and accepting invalid hints - #1877

Open
Alexandre Kohler (kwy404) wants to merge 1 commit into
microsoft:mainfrom
kwy404:fix-inlay-hint-is-precedence
Open

Alexandre Kohler (kwy404) wants to merge 1 commit into
microsoft:mainfrom
kwy404:fix-inlay-hint-is-precedence

Conversation

@kwy404

Copy link
Copy Markdown
Contributor

InlayHint.is has a misplaced parenthesis on the textEdits check: && (candidate.textEdits === undefined) || Is.typedArray(candidate.textEdits, TextEdit.is). Because && binds tighter than ||, this splits the whole guard into two halves joined by ||. When textEdits is undefined, the tooltip, paddingLeft and paddingRight checks are ignored. When textEdits is an array, the object literal, position, label and kind checks are ignored. For undefined or null, the second half reads candidate.textEdits and throws. For example InlayHint.is({ textEdits: [] }) returns true, and InlayHint.is(undefined) throws TypeError: Cannot read properties of undefined (reading 'textEdits') instead of returning false.

The fix moves the closing parenthesis so the check reads (candidate.textEdits === undefined || Is.typedArray(candidate.textEdits, TextEdit.is)), like the other optional property checks in the same function.

I added an InlayHint.is suite to types/src/test/typeguards.test.ts. Before the change the invalid paddingLeft and missing position and label cases fail with true !== false and the undefined case fails with the TypeError above. After it they pass, and a valid InlayHint.create(...) is still accepted. The full types test suite (45 tests) passes and eslint is clean.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The precedence fix is correct and the tests cover both bypass paths and the undefined-input failure.

0 open findings

What changed in this PR

Fixes InlayHint.is validation precedence so invalid inputs return false rather than bypassing checks or throwing.

Changes:

  • Corrects grouping of the optional textEdits check.
  • Adds regression tests for invalid, incomplete, and undefined hints.
File Description
types/​src/​main.ts Corrects the InlayHint.is guard logic.
types/​src/​test/​typeguards.test.ts Adds focused regression coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants