-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Files with .es6 suffix are treated as TypeScript files #7926
Comments
What is happening is that VS Code registers One work around is to disable the error diagnostics from the tsserver for js files in the settings: Moving to TypeScript, there should be a way to configure that |
@egamma Thanks for moving the issue to the right place. Just as a point of information for anyone who finds this and has the same issue:
|
Since we're already discussing file extensions, it would be great if it was configurable which files are supposed to be treated as JavaScript and which as TypeScript. In various projects that we're migrating to TypeScript we decided to stick around with Perhaps a configuration option in |
So why not plugin in TS at the beginning of your build pipeline with
The TS API already has a way to override the ScriptKind, see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.d.ts#L537. VSCode or other editors can leverage this to open any file under any ScriptKind if needed. not sure if this needs to be added to tsconfig.json. |
Not sure what you mean here @mhegazy, since I wasn't talking about the build pipeline. What I'm after is having the whole |
@mhegazy I've just tried manually changing the Language Mode in VSCode on a JS file, but it doesn't have any effect on the way TypeScript interprets the file. On the lines which have type annotations, I'm still getting the error:
|
What i meant is if you copy your .js files to .ts files, and build them using One thing to note, extensions are important to figuring out modules, types, output location, etc.. so i would recommend using the .ts extension when you are adding types, and technically, types are not part of the JS syntax, so the .js extension is misleading.
This sounds like a VSCode issue. @egamma and @dbaeumer any comments on this issue? |
The thing is we don't want to do that until all the typings are there. We want to add typings gradually, and cannot afford adding them all at once. Unfortunately with TypeScript it's all or nothing, because of problems like: let a = {};
a.property = 'a'; // ERROR! Which is valid JavaScript. After changing the extension to |
is your code base modules? have you tried using
The compiler makes assumptions about the files based on their extensions. including finding modules, parsing, reporting errors, etc.. and i believe the editor has enough APIs to enable this if needed. but do not think this needs to be backed in the command line compiler. |
@mhegazy yes, the codebase makes use of modules. I know it's a pretty crazy argument, and I personally don't support it, but these are the circumstances we are and have to handle them appropriately. |
From @jbutz on April 6, 2016 18:12
Steps to Reproduce:
Create a new file with the extension
.es6
and the following codeThe Language Mode is automatically set to "JavaScript", but on
this.myValue
you getProperty 'myValue' does not exist on type 'Testing'
errors.Close the file and rename it to use a
.js
extensionOpen the file and notice that the errors are gone
Copied from original issue: microsoft/vscode#5046
The text was updated successfully, but these errors were encountered: