microsoft / microsoft/vscode-json-languageservice

IntelliSense incorrectly narrows anyOf branches when one variant requires additional properties

Open
#307 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
326
Forks
145
Avg merge
22h 10m
Merged PRs (30d)
9

Description

When authoring against a schema that can branch into a route that requires more properties, or a route that requires no additional properties, VSCode's intellisense has some unexpected behaviour:

Schema:

{
    "anyOf": [
        {
            "type": "object",
            "required": [
                "type",
                "thing"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "const": "A"
                },
                "thing": {
                    "type": "number"
                }
            }
        },
        {
            "type": "object",
            "required": [
                "type"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "const": "B"
                }
            }
        }
    ]
}

Expected behaviour:

Should show both "A" and "B" as possibilities.

Actual behaviour:

Image

Yet, when hovering over the yellow squiggle, it shows this, which is also not true:

Image

Contributor guide

No contributing guide indexed for this repository

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

Reproduce the reported schema in VSCode IntelliSense and compare the suggested values and hover warning with the expected A and B branches. No implementation files or tests are named, so trace the JSON language service's anyOf narrowing behavior first; done means both values are offered without an incorrect warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.