-
-
Notifications
You must be signed in to change notification settings - Fork 209
Possible to use @babel/plugin-transform-typescript
with this?
#663
Comments
I think this is related #692 |
Yeah, there might be some work needed to make sure the AST looks correct with types. I know that in the past @JamesHenry talked about wanting to make sure the ASTs produced by this and typescript-estree matched. Given that the TypeScript team is planning to contribute to ESLint to get the TS experience up to snuff, it would probably be a good idea so that any TypeScript plugins can be used with either. |
Relevant |
The babel implementation may be an option for some folks. Part of the effort to align on ASTs is to facilitate that :) However, I would note that you will miss out on a whole category of linting if you go with babel-eslint for TypeScript support, because the TypeScript compiler is not involved. This means you will not be able to use rules which rely on type information, which can be very useful. So, yes, it definitely has its place and will be a lightweight solution for folks, depending on their use-cases |
Just to double down on it - multiple solutions using shared primitives is a great situation IMO (shared primitive here being the AST) |
ICYMI, announcement following on from what Kai mentions above: https://eslint.org/blog/2019/01/future-typescript-eslint |
Thank you so much for your contribution! People were complaining about TSLint for a long time. |
Yes that's incredible. Thank you so much. Here is my typescript with eslint setup: https://github.com/wcandillon/eslint-config-react-native-wcandillon It's amazing to see how things evolve and how fast they evolve. |
If I don't get it wrong, the new approach If that's it, I'm afraid of that we can't lint |
Use In the view of users, we don't care about how eslint deal with it. We just know that TypeScript support to be able to be parsed by babel is the great success in the stand of users, and I can't take that I need to change my eslint configuration a lot and not be able to lint |
@chengjianhua It actually is possible to specify different parsers for different extensions in ESLint using glob-based configuration. And just to be clear, neither @JamesHenry or myself has suggested that babel-eslint shouldn't support TS. PRs are definitely welcome! |
Based on the response I received in the typescript-eslint/parser repo regarding support for babel proposal plugins, it seems like babel-loader support (or at least not blowing up) w/ typescript is the only option forward. They have no plans to support proposals. |
Until last year, the TypeScript compiler was the way that TypeScript source code was parsed. Now there are two ways:
This is a fork in the road when it comes to parsing.
It is great that we have more than one solution - but it is not possible to mix and match the parsing option from one and linting option from another right now (nor is there anything planned). Please note, the TypeScript compiler is still the only way to type check your code. Babel parses and strips the type information, you still need the TypeScript compiler running if you want type checking. |
@chengjianhua As Kai explains, you are not correct. As of right now, the typescript-eslint codebase itself is a mixed JS and TS project, for example. It is very much possible for ESLint to be configured to use different parsers for different file types. |
@JamesHenry that makes sense. If I want to keep in babel land but still add typescript types on top of it can I use babel-eslint w/ typescript-eslint/plugin? |
That's exactly what this issue is open for :) I'm personally not sure if there are any blockers right now, so I can't comment either way. My focus has been on typescript-eslint recently, I hope to contribute to babel-eslint more again in the future |
I'm not aware of any blockers for adding support for TypeScript, now that One thing this project needs to decide is if it's planning to track and match the shape of the AST generated by Note that |
Is there any way to run the typescript compiler and use babel proposals? It works w/ eslint when using babel-eslint but I still haven't found a way to run tsc when using proposals that aren't supported by typescript such as null coallescing or optional chaining. |
@JamesHenry Thanks~ I'm glad to see that I was wrong. If it's able to configure different parsers for various extensions, it eliminated my doubts basically.
|
at @typescript-eslint we are doing alignment tests of AST generated by babel We are also tracking difference between generated output there is few major differences in generated AST
and few nodes needs postprocessing to match AST generated by @typescript-eslint:
you can also check "big" alignment test project typescript-estree-test, i'm going to extend tests to cover |
[@typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) seems to be the way to go since it actually uses TypeScript under the hood. The alternative is Babel, which "parses and strips the type information, you still need the TypeScript compiler running if you want type checking." see [babel/babel-eslint#63](babel/babel-eslint#663 (comment)) [The future of TypeScript on ESLint (Jan 2019)](https://eslint.org/blog/2019/01/future-typescript-eslint) Closes #51
Hi, module.exports = {
parser: "babel-eslint",
overrides: [
{
files: ["**/*.ts", "**/*.tsx"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
// If adding a typescript-eslint version of an existing ESLint rule,
// make sure to disable the ESLint rule here.
rules: {/*...*/}
}
],
}; Is this the (currently) correct way? Is it planned in the future that we can only use babel-eslint for both? |
@PutziSan did work for you? I'm trying the same setup but is not working for me |
I work almost exclusively with TypeScript now and don't use eslint at the moment. |
Thank you for the issue. Now that |
I'm wondering if I can use
@babel/plugin-transform-typescript
along withbabel-eslint
instead oftypescript-eslint-parser
.The text was updated successfully, but these errors were encountered: