6

I'm working in PhpStorm on a Vue 2 / TypeScript project where whenever I want to include return types on functions I get "Types are not supported by current JavaScript version":

Types are not supported by current JavaScript version

On "Preferences > Languages and Frameworks > JavaScript", I have ECMAScript 6+ selected:

selected

I've tried restarting the IDE to no avail.

Any ideas?

4
  • 4
    JavaScript doesn't have type annotations. You need to use Flow or TypeScript or (potentially) other things that allow for using types. Commented May 19, 2021 at 8:39
  • 1
    just modify file extension. replace js with ts Commented May 19, 2021 at 9:11
  • 4
    Such a weird error message really. I mean, it is as if types are just about to be supported in the nearest version of JavaScript. Commented May 19, 2021 at 9:12
  • 1
    @DimaParzhitsky I agree. VSCode has the better one Type annotations can only be used in TypeScript files Commented May 19, 2021 at 9:14

2 Answers 2

6

Ah, apparently I was misled by the wording of the error message. Simply adding <script lang="ts"> inside my vue files has fixed it.

Sign up to request clarification or add additional context in comments.

1 Comment

exactly - without lang attribute, the <script> language is assumed to be javascript, thus the message
3

I had the same error, but it happened because I was writing Typescript code in a .js file instead of .ts file.

  1. Rename .js to .ts
  2. Make sure you have the Javascript language version set to ECMAScript 6+ under Languages & Frameworks > Javascript in your Jetbrain IDE.

1 Comment

thanks Hyder! this helped me in Webstorm. My extension was .js instead of .ts out of habit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.