microsoft / microsoft/monaco-editor

[Bug] Consecutive calls to `setExtraLibs` fails to update an interface definition

Open
#3,465 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug typescript typescript-multifile
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Code
function updateModelDefinition(propertyName) {
    var filePath = 'ts:filename/model.d.ts';
    var content = `interface Model { ${propertyName}: string }`;
    monaco.languages.typescript.typescriptDefaults.setExtraLibs([{filePath, content}]);
}

monaco.editor.create(document.getElementById('container'), {
	value: `const test: Model = {}`,
	language: 'typescript'
});

// This call works as expected
updateModelDefinition("immediate")

// Bug: Any future calls to setExtraLibs seem to be ignored
setTimeout(() => updateModelDefinition("afterTwoSeconds"), 2000);

setTimeout(() => updateModelDefinition("afterFiveSeconds"), 5000);
Reproduction Steps

Click run in the playground and wait a few seconds to let the timeouts fire and observe that the consecutive calls to setExtraLibs does not have the expected effect.

Actual (Problematic) Behavior

The editor keeps using the code provided by the first call to setExtraLibs, even if its called multiple times with new input.

Observe that the error in the playground example is incorrect:
Property 'immediate' is missing in type '{}' but required in type 'Model'.

Expected Behavior

The editor should respect the most recent call to setExtraLibs.

The playground example should after 2 seconds yield the error:
Property 'afterTwoSeconds' is missing in type '{}' but required in type 'Model'.

The playground example should after 5 seconds yield the error:
Property 'afterFiveSeconds' is missing in type '{}' but required in type 'Model'.

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 Monaco Editor Playground reproduction and the typescriptDefaults.setExtraLibs calls shown in the issue. Trace how successive calls are processed and compare the observed diagnostics with the expected latest interface definition. Done means each update is reflected in the editor, with afterTwoSeconds and afterFiveSeconds replacing the earlier property name.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.