LSP-typescript: Using Flow in React Project. Type annotations can only be used in TypeScript files error.

In my react\javascript project i use Flow, and often get this error: error Type annotations can only be used in TypeScript files. ​typescript:8010

How can i disable it?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (15 by maintainers)

Most upvoted comments

It’s a problem that both plain JS and flow use the same syntax since the syntax (or its root scope) is currently the way to map language servers to files that they run on.

The only solution I can think of is to:

  • use bundled Javascript syntax for *.js files by default
  • make your JSCustom syntax not apply to *.js files by default
  • use https://packagecontrol.io/packages/ApplySyntax to assign the flow syntax to flow files by checking the first line for // @flow.

Wow, that’s great, thank you! However, looking at ST’s docs, first_line_match comes into play only when a file is opened without a recognized extension. That wouldn’t work for .js files, no?

Good idea. I’ve added a first_line_match option to JS Custom and you can try it out in v4.2.0-beta.5.