Vscode: 'Type aliases can be used only in a .ts file' error popping up in Flow enabled files

Created on 8 Nov 2016  路  14Comments  路  Source: microsoft/vscode

  • VSCode Version:
    1.7.1
  • OS Version:
    Ubuntu 16

Steps to Reproduce:
Create a .js file and add the following code in it(the file will be processed by Flowtype):

// @flow
type LogActionsType = { type: 'NEW_LOG', payload: Array<Object> } | { type: 'LOGS_PUSHED', payload: null };
export type LogType = Object

Whenever I define a type alias the error 'Type aliases can be used only in a .ts file' keeps showing up and is highlighed in the 'Problems' panel.
Is there any way to disable typescript ? Or prevent this kind of validation of running ?

*not-reproducible javascript

Most helpful comment

I still got this error with Flow 0.40 using VSCode 1.10.2.

// .vscode/settings.json
{
  "javascript.validate.enable": false,
  ...
}

UPDATED

Sorry, after restarting VSCode, this error was gone.

All 14 comments

Got the same issue:

  • VSCode Version: Code 1.7.1 (02611b40b24c9df2726ad8b33f5ef5f67ac30b44, 2016-11-03T13:46:00.226Z)
  • OS Version: Darwin x64 15.6.0

// @Flow annotation at top of file.

and javascript.validate.enable": false in my Workspace settings.

Error highlighted:

[js] 'types' can only be used in a .ts file.
[Flow]
string: (object: Object) => Array<string>

Confirmed on latest bits. Moving to TS Server repo.

This issue was moved to Microsoft/TypeScript#12186

Reopening here. The suggestion from TS team recommends this be handled on VS Code's side.

The recommendation is for VS Code to check to see the Flow annotation and not pass it on to the TS Server.

@dbaeumer this looks like something we should look into soon as it can be a poor experience for flow users.

@waderyan this should not go into the TS extension. We shouldn't parse the first line. There are two ways to deal with this:

  • users disable JS validation using javascript.validate.enable": false
  • users install a flow extension which add flow language mode. Then these files will not be synced over to the tsserver.

I tested that if I set javascript.validate.enable": false that the error is not shown.

capture

@waderyan recommend to close.

I still got this error with Flow 0.40 using VSCode 1.10.2.

// .vscode/settings.json
{
  "javascript.validate.enable": false,
  ...
}

UPDATED

Sorry, after restarting VSCode, this error was gone.

I still got this error with Flow 0.40 using VSCode 1.10.2.

I still got this issue with VSCode 1.13.1.
After restarting VSCode, the issue is going away. But it's only a matter of time before it comes back. I find myself having to restart VSCode at least once per hour, which is quite annoying.
I've got javascript.validate.enable set to false.

I was able to resolve by doing the following:

  1. Set javascript.validate.enable to false
  2. Move .flowconfig from my src dir to the workspace root
    Hope this helps.

I am also still getting this error. I have the .flowconfig in my root and set javascript.validate.enable to false. Any troubleshooting steps would be appreciated.

foo1
foo2

I'm on vscode Version 1.14.2 (1.14.2) and flow ^0.42.0

Maybe this will be helpful for someone, ... what I did (i think) to finally get ts to stop was adding .tsconfig

{
    "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "outFile": "../../built/local/tsc.js",
        "sourceMap": true
    },
    "include": [
    ],
    "exclude": [
        "**/*.js"
        "node_modules",
    ]
}

@foobar8675 the problem is still there:

image

I writed this file: ".tsconfig" in root folder (tried also in just "./src" folder), reloaded VSCode and still the problem.

.tsconfig:

{
  "compilerOptions": {
    "module": "system",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "outFile": "../../built/local/tsc.js",
    "sourceMap": true
  },
  "include": [],
  "exclude": ["**/*.js", "node_modules"]
}

@johnunclesam sorry, i have no idea what the issue is then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sirius1024 picture sirius1024  路  3Comments

mrkiley picture mrkiley  路  3Comments

lukehoban picture lukehoban  路  3Comments

villiv picture villiv  路  3Comments

biij5698 picture biij5698  路  3Comments