profile
viewpoint

Ask questionsTypeScript declaration preview from extra lib results in error

<!-- Do you have a question? Please ask it on https://stackoverflow.com/questions/tagged/monaco-editor --> monaco-editor version: 0.17.0 Browser: IE, Chrome, Firefox OS: Windows 10

The TypeScript declaration preview does not work for declarations added through monaco.languages.typescript.javascriptDefaults.addExtraLib() and causes an error.

Steps or JS usage snippet reproducing the issue:

  1. Go to the Configure JavaScript defaults playground example
  2. Trigger the declaration preview on Facts (hover while pressing Ctrl)

This results in the following error:

Error: [UriError]: Scheme is missing: {scheme: "", authority: "", path: "filename/facts.d.ts", query: "", fragment: ""}
    at editor.main.js:209
    at t.e (editor.main.js:210)
    at new t (editor.main.js:211)
    at Function.e.parse (editor.main.js:211)
    at tsMode.js:7
    at async Promise.all (index 0)
    at editor.main.js:38
microsoft/monaco-editor

Answer questions blutorange

Not sure if this is intentional or not, but this can be fixed by adding a scheme (eg. inmemory) to the file path given to addExtraLib. In the example above from the playground on lines 19-26, it should read:

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

(inmemory:filename/facts.d.ts instead of filename/facts.d.ts)

useful!

Related questions

Monarch: How do you add "@keywords" key to "language object"? (undocumented) hot 3
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/gotoSymbol/goToCommands' hot 2
Removing the tooltip on the read-only editor that says &#39;cannot edit in read-only editor&#39; hot 1
Monaco paste event hot 1
Registering/Providing custom Commands/CodeActions hot 1
How to get the line count including line wraps hot 1
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/goToDefinition/goToDefinitionCommands' hot 1
Editor props/extends the actual width of the parent that is a flexbox item hot 1
Problem with insane.js while using monaco-editor@0.18.0 hot 1
Change the language of an existing editor hot 1
javascript/typescript typedefs lost when webworker times out hot 1
Can't scroll in firefox hot 1
How to add simple custom language support? hot 1
monaco-editor polute the global variables, making incompatible with other JS libraries, such as CodeMirror, RequireJS, SeaJS, etc. hot 1
Highlight merge conflicts in monaco like in VSCode hot 1
Github User Rank List