How to scope intillisense down to just passed in `.d.ts` defs.
I’m looking at the configuration options for the VSCode MonacoEditor related to specifying intellisense via .d.ts definitions:
Playground: Configure JS Defaults Example
// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true
});
// extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([
'declare class Facts {',
' /**',
' * Returns the next fact',
' */',
' static next():string',
'}',
].join('\n'), 'filename/facts.d.ts');
var jsCode = [
'"use strict";',
'',
"class Chuck {",
" greet() {",
" return Facts.next();",
" }",
"}"
].join('\n');
monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "javascript"
});
I’m wondering if there is a way to scope intillisense down to just the types passed in via addExtraLib - at the moment the kitchen sink of ES6 is available in the dropdown lists, including all of HTML5 for the browser etc etc.
For my purposes, I’m having the editor run in a tightly constrained environment so most of the API surface area represented in these dropdowns in not relevant.
The target field of setCompilerOptions seems likely, but in playing around with that it doesn’t seem to have any effect on reducing scope, eg all of these options don't narrow scope at all:

ref Playground
Any ideas? It feels like this must be somewhere else in the API, yeah? Thanks 🌵
You can pass 'nolib' option to setcompileroption.
Thanks @yln99517 - that's great.
Setting nolib to true seems wipes out the HTML/Browser centric intillisense, and I am just getting my passed in .d.ts.
As a follow-on question, how would I go about dealing with this "No Promise" error:

I'm setting noLib and then passing in ES2015 to lib as suggested, but no dice:
const typescript = monaco.languages.typescript;
typescript.typescriptDefaults.setCompilerOptions({
noLib: true,
lib: ['ESNext', 'ES2015'],
target: typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
});
This has the same effect to (dropping the noLib in favor explicitly passing the lib array, which I'm wildly guessing at being the sameis effect:
const typescript = monaco.languages.typescript;
typescript.typescriptDefaults.setCompilerOptions({
lib: ['ESNext', 'ES2015'],
target: typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
});
Any ideas? Thanks!
You need to extract required libs from default libs then pass to addExtraLib. It solves the problem.
Thanks @yln99517. Where do I find the "default libs" to extract from?
I wonder if you might be able to give me a brief code sample to get me going in the right direction please @yln99517 ?
Hi , Goto this. You can see available libs or default libs. Pack required libs into one file or in a string. Pass the string to addExtraLib. Hope this helps. thanks
@yln99517 - sweet! That's perfect, thanks!