Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
monaco-editor – Type annotations can only be used in TypeScript files.(8010)

I can't get why monaco-editor can't work with typescript files.

Here is the source code I passed into the editor:

import React from 'react';
import styles from './Test.scss';

export const Test = (foo: number) => {
    return (
        <div className={styles.container}>Test</div>
    );
}

And the options:

Language = typescript +

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
      target: monaco.languages.typescript.ScriptTarget.Latest,
      allowNonTsExtensions: true,
      moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
      module: monaco.languages.typescript.ModuleKind.CommonJS,
      noEmit: true,
      esModuleInterop: true,
      jsx: monaco.languages.typescript.JsxEmit.React,
      reactNamespace: "React",
      allowJs: true,
      typeRoots: ["node_modules/@types"],
    });

So I told the editor "here is a typescript file", but that foo: number show error Type annotations can only be used in TypeScript files.(8010)

How to deal with it?

P.S. It's a web application, i.e. monaco-editor is not inside VS code

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You didn't set the language to "typescript". All the settings you have here are on top of the base language (e.g. JSX support, script target, module resolution etc.).

To set a language use either editor.setModelLanguage(yourModel, "typescript"); (if the model exists already, e.g. the default one in the editor) or create your own model and specify the language in the creation call: editor.createModel(content, language, uri);.

Check ITextModel.getModeId(); to see if it uses the correct language.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!