Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monaco Editor - how to disable errors (typescript)

I'm using Monaco for Typescript code with the ngx-monaco-editor library. Everything works great except that I want to disable the errors.

enter image description here

How can I disable

  • all errors (like syntax, imports not found, anything)
  • selective like 'experimental decorators'

I can see that the library is calling

this.initMonaco(options, this.code, this.language);

..but options seem to the only editor options, not typescript compiler options, and code and language, just strings.

How can I tell monaco what compiler options to use?

like image 547
Hoff Avatar asked Jul 09 '19 13:07

Hoff


People also ask

What is Monaco editor in Visual Studio Code?

The Monaco Editor is the code editor that powers VS Code. It’s a JavaScript library that offers an API for syntax highlighting, auto-completion, etc. TypeScript, webpack, webpack-dev-server, webpack-cli, HtmlWebpackPlugin, and ts-loader. So let start by initiating the project.

How to enable syntax highlighting in the Monaco editor?

To tell Monaco to consider this configuration, go the set-up function, in the onLanguage callback, call monaco.languages.setMonarchTokensProvider, and give it the configuration as the second argument: Run the app. the editor should now support syntax highlighting. Here is the source code of the project so far: amazzalel-habib/TodoLangEditor.

Is the Monaco editor on npm transpiled and published as JavaScript?

The Monaco editor package on NPM is transpiled and published as JavaScript. However, using the Monaco package requires that we use Webpack as it still contains import statements for CSS files. We also need to load a few scripts as web workers to improve the editor's performance. For Snack, we use Next.js 4, which is still on Webpack 2.

Is it possible to implement a custom language feature in Monaco?

While trying to replicate this feature in Monaco, we realized we would have to create an entirely custom language feature and bolt it onto the built-in Javascript language definitions and handler in Monaco. During this process we ran into a few problems, including:


2 Answers

Try calling this method:

monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
  noSemanticValidation: true,
  noSyntaxValidation: true,
});

It will prevent any kind of semantic or syntax errors in your monaco code.

like image 106
yurzui Avatar answered Oct 20 '22 22:10

yurzui


You can also specifically disable individual errors

monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
  diagnosticCodesToIgnore: [1109]
})

1109 is an example of the error code shown in the hover tooltip in Monaco. Add whichever errors you want to hide to that array.

like image 31
ndom91 Avatar answered Oct 20 '22 22:10

ndom91