I'm using Monaco for Typescript code with the ngx-monaco-editor library. Everything works great except that I want to disable the errors.
How can I disable
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?
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.
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.
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.
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With