microsoft / microsoft/monaco-editor
[Bug] imports of a preloaded extraLib inside another extraLib fail
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
monaco.languages.typescript.typescriptDefaults.addExtraLib(
`
declare module 'sausage.js' {
class Sausage {
foo(): void;
}
export {Sausage};
}
`
);
monaco.languages.typescript.typescriptDefaults.addExtraLib(
`
import * as SausageLib from 'sausage.js';
declare namespace SausageFactory {
function newSausage(): SausageLib.Sausage;
}
`
);
monaco.editor.create(document.getElementById('container'), {
value: `import * as SausageLib from 'sausage.js';
// Works
(new SausageLib.Sausage()).foo();
// Should work; partially works only if 'sausage.js' is not imported in the second extraLib.
var q = SausageFactory.newSausage();`,
language: 'typescript'
});
Actual Behavior
The second extraLib (the one with SausageFactory namespace`) fails without any errors; its typings are missing.
Expected Behavior
The second extraLib should load just fine, including the typings derived from the 'sausage.js' module.
Additional Context
So my instances of editors should load two large libraries: one as a module (a 3rd-party chonk of .d.ts) and another as a namespace (my typings), and this namespace extends a lot of classes from that 3rd-party module and uses its types, too, so it needs the module to import to provide complete typings to the end-user.
Right now I can only load them both if I don't import the 'sausage.js' inside my own library's typings, but that kinda destroys the point of having typings as they become incomplete for the namespaced library.
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
Start with the supplied Monaco Editor Playground snippet and the two typescriptDefaults.addExtraLib calls. Reproduce the missing SausageFactory typings, then trace how imported declarations from one extraLib are registered and resolved by the TypeScript integration. Done means the namespace retains its imported Sausage type when both extraLibs are loaded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100