experimenting-with-babel-7-typescript-and-eslint icon indicating copy to clipboard operation
experimenting-with-babel-7-typescript-and-eslint copied to clipboard

Project status

Open LaszloDev opened this issue 5 years ago • 20 comments

My requirements are mostly the same and I ran into the same issues.

Did you check recently for any improvements?

LaszloDev avatar Jul 07 '19 22:07 LaszloDev

I too am curious about an update. Has anyone gotten enums to be recognized by babel-eslint?

brendanoffer avatar Aug 13 '19 02:08 brendanoffer

So babel-eslint 10 actually works much better, but fails to understand specialized syntax like a! as number or newer typescript parts like unknown.

krainboltgreene avatar Aug 27 '19 05:08 krainboltgreene

for some reason this setup throws an error on static keyword

export class XX {
  public static xx = 123;
}

TrejGun avatar Aug 28 '19 04:08 TrejGun

Hey! I'm also making experiment of ts-loader vs babel plugin. For a minimal project, I got -30% bundle size and x3 faster compilation.

Please, take a note: https://github.com/babel/babel-eslint#breaking-change-in-v11xx

nrei0 avatar Oct 25 '19 08:10 nrei0

@Ateiri and you dont have errors I mentioned here https://github.com/babel/babel-eslint/issues/797 ??

TrejGun avatar Oct 25 '19 12:10 TrejGun

@TrejGun no-no, sorry that confused, I didn't check full TS support from babel-eslint@11, but in a case, if support is limited as you mention, we need to aggregate all problems and raise a ticket in babel-eslint's repository.

I will check TS syntax support in babel-eslint a bit later, also have a lot of to do for now.

nrei0 avatar Oct 25 '19 12:10 nrei0

Is this reported to developers of babel/babel-eslint ?

tavrez avatar Dec 17 '19 16:12 tavrez

yes, they are working on babel8 currntly which is going to support eslint and typescript much better

TrejGun avatar Dec 18 '19 02:12 TrejGun

Reading on https://babeljs.io/docs/en/babel-plugin-transform-typescript, it looks like babel does not have a type system. I don't think it will be implemented any time soon (hopefully I'm wrong).

For now it's either tsc or babel + flow

zys5945 avatar Feb 11 '20 04:02 zys5945

yes, babel won't implement types

you can still use https://github.com/typescript-eslint/typescript-eslint

TrejGun avatar Feb 11 '20 04:02 TrejGun

Have you tried your tests with new Babel parser? @babel/eslint-parser

tavrez avatar Aug 10 '20 22:08 tavrez

Hey, I've just done this! It's much more possible now than before, but some room to grow. To be clear I have project using:

  1. babel 7
  2. eslint 4
  3. typescript 4

To get this done you need:

  1. @babel/eslint-parser
  2. @babel/eslint-plugin
  3. @babel/preset-typescript
  4. You need to tell eslint to bother with .ts(x), which includes the eslint extension in vscode (It's the "eslint.validate" and "eslint.probe" property, if you're curious)

How far will this get you?

  • eslint will now be able to parse your .ts(x) and .js(x) files just fine
  • typescript will be able to typecheck your .ts(x) files just fine
  • babel will be able to parse your .ts(x) and .js(x) files just fine
  • vscode does all the above

I would prefer eslint to also report what tsc pops out, but fuck it I'll take what I can get. You also can't use @typescript-eslint/eslint-plugin so no fancy rules.

krainboltgreene avatar Aug 28 '20 08:08 krainboltgreene

here is what i have found https://github.com/babel/babel/issues/11975

TrejGun avatar Aug 28 '20 13:08 TrejGun

Hmm, I haven't even run into that yet, but I suspect I will.

krainboltgreene avatar Aug 28 '20 17:08 krainboltgreene

Okay, I've found one annoyance:

Screen Shot 2020-09-01 at 12 26 49 PM Screen Shot 2020-09-01 at 12 26 45 PM

krainboltgreene avatar Sep 01 '20 19:09 krainboltgreene

@krainboltgreene

I am trying to combine @babel/eslint-plugin with TypeScript as well. Do you have any updates for us?

tafelnl avatar Feb 03 '21 11:02 tafelnl

Apparently, recently, Babel made their point of view about this clear in the README: https://github.com/babel/babel/pull/12222/files

TLDR: They do not officially support it because they "want to avoid duplicate work". So for any type-aware rules it seems like we should just resort to @typescript-eslint

tafelnl avatar Feb 03 '21 12:02 tafelnl

Yeah I poked at them in their slack channel about this and it's basically never going to work well together. I've completely abandoned the idea honestly. Non-typescript projects get babel-eslint and typescript projects get typescript-eslint.

krainboltgreene avatar Feb 03 '21 18:02 krainboltgreene

i do this in the same way https://github.com/TrejGun/trejgun-eslint-config

TrejGun avatar Feb 04 '21 00:02 TrejGun

I have the following working for a mix mode project as i transition it to typescript, it seems to work so far with gulp-eslint and vscode eslint.

packages.json

{
    "@tsconfig/node16": "^1.0.2",
    "@typescript-eslint/eslint-plugin": "^5.10.0",
    "@typescript-eslint/parser": "^5.10.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.26.0",
    "eslint-plugin-jest": "^24.3.6",
    "gulp-babel": "^8.0.0",
    "gulp-eslint": "^6.0.0",
    "typescript": "^4.5.4",
    "@babel/core": "^7.14.0",
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.13.8",
    "@babel/preset-env": "^7.14.1",
    "@babel/preset-typescript": "^7.16.7"
}

.eslintrc

{
  "settings": {
  },
  "plugins": ["jest"],
  "parser": "babel-eslint",
  "env": {
    "node": true,
    "es6": true,
    "jest": true
  },
  "rules": {},
  "overrides":[{
    "files": ["*.ts"],
    "parser": "@typescript-eslint/parser",
    "plugins": ["@typescript-eslint"],
    "extends": [
      "eslint:recommended",
      "plugin:@typescript-eslint/recommended"
    ],
    "rules": {
      "quotes": [2, "double"]
    }
  }]
}

tsconfig.json

{
  "extends": "@tsconfig/node16/tsconfig.json",
  "compilerOptions": {
    "allowJs": true,
    "noEmit": true,
    "removeComments": false,
    "preserveConstEnums": true,
    "outDir": "lib/",
    "sourceMap": true,
    "esModuleInterop": true,
    "isolatedModules": true
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

.babelrc

{
  "presets": [
    [
      "@babel/preset-env", {
        "targets": {
          "node": "current"
        },
        "useBuiltIns": "usage",
        "corejs": "3"
      },
    ],
    "@babel/preset-typescript"
  ],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-proposal-class-properties"
  ]
}

Azerothian avatar Jan 19 '22 01:01 Azerothian