microsoft / microsoft/monaco-editor
[Bug] Using incorrect lib in setCompilerOptions causes unexpected autocomplete failures
Nobody has claimed this yet.
- 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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Code
const content = `export type Args =
| { foo: number, bar: number }
| { foo: number }
| { bar: number };
declare global {
class FooBar {
public static foo(opts: { args: Args }): void
}
}
`
const options = monaco.languages.typescript.typescriptDefaults.getCompilerOptions();
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ ...options, lib: ['ESNext'] });
monaco.languages.typescript.typescriptDefaults.setExtraLibs([{ content, filePath: 'test.d.ts' }]);
monaco.editor.create(document.getElementById('container'), {
value: `FooBar.foo({ args: {} })`,
language: 'typescript'
});
Reproduction Steps
After loading the above code in the playground, move the cursor into the args: {} object and trigger autocomplete with ctrl+shift.
Actual (Problematic) Behavior
Upon triggering autocomplete you will not see the foo or bar properties available in the autocomplete popup.
However if you change the playground code content variable to:
const content = `export type Args = { foo: number, bar: number };
declare global {
class FooBar {
public static foo(opts: { args: Args }): void
}
}
`
The autocomplete works as expected.
Expected Behavior
We expect the autocomplete to work in both cases. setCompilerOptions should complain about invalid lib values.
Additional Context
@adrienmaillard and I worked around this problem in our project by using the correct lib string in setCompilerOptions:
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ ...options, lib: ['esnext'] });
A possible path to helping with this is to strongly type the lib property in CompilerOptions. The TypeScript documentation on lib uses uppercase which led us to this issue in the first place.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the autocomplete failure in the Monaco editor playground using the supplied TypeScript snippet, then inspect the lib property in src/language/typescript/monaco.contribution.ts around line 97. Compare the accepted value with the TypeScript lib documentation and verify that invalid values are rejected and autocomplete works for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100