microsoft / microsoft/monaco-editor

[Bug] imports of a preloaded extraLib inside another extraLib fail

Open
#2,850 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug 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
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.