Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot require contents of '.d.ts' files as string in browser for addExtraLib method #758

Closed
jacobdlewis opened this issue Mar 14, 2018 · 2 comments
Labels
feature-request Request for new features or functionality typescript typescript-multifile
Milestone

Comments

@jacobdlewis
Copy link

jacobdlewis commented Mar 14, 2018

monaco-editor version: 0.X.Y

Browser: Chrome Version 64.0.3282.186 (Official Build) (64-bit)

OS: High Sierra 10.13.2

Issue

I want to get autocomplete functionality for a third-party library, like lodash, in my Monaco instance. I'm using the addExtraLib method to make this happen, and I'm having trouble getting access to a valid content argument to provide to it.

It seems that the content argument needs to be the actual content of whatever .d.ts file you want to use, and I am unable to require the typings file via import in the browser.

Examples where content is defined in the file work just fine for me:

monaco.languages.typescript.javascriptDefaults.addExtraLib([
    'delcare class Facts {',
    '    /**',
    '     * Returns the next fact',
    '     */',
    '     static next():string',
    '}',
].join('\n'), 'filename/facts.d.ts');

screen shot 2018-03-14 at 3 51 37 pm

However, this won't work for a larger library, as this would require manually updating the hardcoded content value any time the definitions file is changed.

Attempting to import the type definitions with import * as _ from '@types/lodash results in the following error [ts] Cannot import type declaration files. Consider importing 'lodash' instead of '@types/lodash'. However, importing lodash itself and providing that as the content argument for addExtraLib doesn't work either. It's importing the actual javascript library and doesn't communicate any type information to Monaco.

How can I require the contents of a d.ts file as a string in the browser/how can I add auto-complete for a third-party library in Monaco?

@cdrini
Copy link

cdrini commented Oct 16, 2020

I was able to get lodash working using raw-loader. Definitely doesn't feel like the right solution, but it's currently the only working one I was able to find :P Here are the steps: https://gist.github.com/cdrini/9de507f6ac19da30fd27c5f618783b31

@hediet
Copy link
Member

hediet commented Mar 2, 2023

We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding, and happy coding!

@hediet hediet closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality typescript typescript-multifile
Projects
None yet
Development

No branches or pull requests

4 participants