monaco-editor version: 0.10.1
Browser: All
OS: Windows
I so want the editor to recognise undeclared variables. So I looked through the API docs and thought. Mmmm, simple:
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true,
/* but the settings below seem to be ignored */
alwaysStrict: true,
noImplicitUseStrict:true,
noUnusedLocals:true
});
How can I set the editor to strict mode? In the past this has been simple using ES6Lint and another editor. A solution to this would be gratefully received. Thanks in advance. David
@David-Carty The following code works fine for me in the Monaco Editor Playground.
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
noSyntaxValidation: false
});
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true,
alwaysStrict: true,
noUnusedParameters: true,
noImplicitUseStrict: true,
noUnusedLocals: true
});
var jsCode = [
'"use strict";',
'function x(unusedParam) {',
'\tvar unusedVar = 0;',
'}'
].join('\n');
monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "javascript"
});
@rcjsuen Thank you so much for your solution. So utterly grateful to this community. Have a fab day!
@David-Carty Happy to help. In the future, please ask your question on Stack Overflow instead of opening an issue on GitHub.
If you have no further questions with your current issue, please close this issue. Thank you!
Thanks again. Will post on Stack moving fwd.
Most helpful comment
@David-Carty The following code works fine for me in the Monaco Editor Playground.