-
Notifications
You must be signed in to change notification settings - Fork 11
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
Using Flow in React Project. Type annotations can only be used in TypeScript files error. #60
Comments
You don't want to run LSP-typescript in a flow project. You might want to use |
We have a huge project that has both Flow (older code) and TS (newer code), and I'd prefer to keep |
Is the root scope different in the flow syntax you are using? For plain javascript syntax it's If the root syntax is different then we (or you) could do something about it. Otherwise probably not as checking for existence of some sub-scopes in the scopes is a bit too much IMO. |
I don't think that's possible. JS Custom can be told to set a custom root scope, by the looks of it, but then all JavaScript files, even the ones not covered by Flow, would be marked as |
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:
|
A .sublime-syntax can have a first_line_match too. That would alleviate the need for ApplySyntax. However, I don’t know whether JSCustom can be configured in such a way to add a first_line_match (and no extensions) for a generated syntax. Maybe @Thom1729 can shed a light on this? |
Good idea. I've added a |
Wow, that's great, thank you! However, looking at ST's docs, |
Hmm, evidently not. It looks like it might be a job for ApplySyntax after all. Out of curiosity, how do you/how does your build system differentiate between the Flow and TS files? |
No problem! The project is transpiled by Babel, all types are just stripped away. Static analysis is separate, Flow runs only on files with |
I've configured ApplySyntax + JS Custom so that they set the scope to For future readers, my JS Custom config: {
"configurations": {
"Flow": {
"scope": "source.js.flow",
"flow_types": true,
"jsx": true
}
}
} And my ApplySyntax config: {
"syntaxes": [
{
"syntax": "User/JS Custom/Syntaxes/Flow",
"match": "all",
"rules": [{ "file_path": ".*\\.jsx?$" }, { "first_line": "^// @flow" }]
}
]
} |
In "selector": "source.js -source.js.flow",
If that works then you can potentially extend it with |
If you set the scope in the JSCustom config to something like |
@rwols that would probably work but would likely break a lot of things (packages, snippets) that depend on |
I see. Maybe we need an exact match instead of a selector match. Or exclude this source.js.flow scope in language-ids.sublime-settings. |
Created #84 |
This is excellent, thank you everybody! Should I document the ApplySyntax + JS Custom part in the readme? |
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?
The text was updated successfully, but these errors were encountered: