Tslint: Unclear how to enable type checking after removing `--type-check`

Created on 26 Oct 2017  ·  14Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.7.0
  • __TypeScript version__: 2.5.3
  • __Running TSLint via__: CLI

TypeScript code being linted

// code snippet

with tslint.json configuration:

{
  "linterOptions": {
    "typeCheck": true
  }
}

Actual behavior

No type checking happens.

The latest tslint recommends removing --type-check. I now run tslint --project tsconfig.json --config tslint.json. Even though I have typeCheck: true in my tslint.json, no type checking is performed if I remove the deprecated --type-check.

Is there a new config I am supposed to specify beyond adding typeCheck: true?

Expected behavior

Type checking happens

Documentation Not A Bug

Most helpful comment

Yep but this change's completely killed pre-commit hooks. It seems like now it's possible to commit broken changes

All 14 comments

We are removing type checking as a feature of TSLint, that's why we deprecated the CLI flag. Type checking errors should be reported by the compiler, not the linter.

Ah! I was unaware of that large change.

It seems like that change of functionality should be very clearly communicated. Am I safe to assume that type checking will continue to work at least until the next major version?

I don't consider it a huge change... we are still allowing rules to _use_ the type checker in their implementations. See here for more info https://github.com/palantir/tslint/pull/3322#issuecomment-338641406

Yeah, we can call it out more loudly in future release notes.

Yep but this change's completely killed pre-commit hooks. It seems like now it's possible to commit broken changes

@nervebassmaster That means you are probably using the wrong tool. Use tsc --noEmit in your precommit hook to make sure there are no compile errors

@ajafff And what is the best way to do the same if I use ts-node instead of tsc

I guess I see. I found the issue in my script.
thx, @ajafff

To anyone subscribed into this issue who is still interested in a way to have type errors as part of the linter output:
I wrote my own linter runtime in the meantime. It has the ability to run TypeScript's type checker as a lint rule. See this recipe for more information.
It can even run TSLint rules, which is described here.

I was considering using tsc --noEmit but that adds about 7 more seconds to our build time for each package, while tsling with --type-check is only ~0.9 seconds, I'm assuming a lot of the work is duplicated between both tools.

I understand the design decision from technical perspective to remove typechecking from tslint. However as Miguel pointed out it has negative usability effect.

More devs will be bumping into this when they remove the deprecating no-unused-variable option and try to use the compiler options (noUnusedLocals and noUnusedParameters) instead.

So if I want to do both typechecking and linting using npm scripts I need to do something like:

"lint": "yarn typecheck && yarn tslint",
"tslint": "tslint --project tsconfig.json --config tslint.json '{src,test}/**/*.ts'",
 "typecheck": "tsc --project tsconfig.json --noEmit"

and then I can just:
yarn lint

This is slower and much more script code than before... I wouldn't be surprised if someone will write a wrapper or fork that does both.

So basically, I can't use no-floating-promises in VSCode without doing some weird workaround instead of using the plugin. Me no like

See https://github.com/Microsoft/typescript-tslint-plugin for a _(n experimental, for now)_ VS Code plugin that works with typed rules.

I really hope that the maintainers listen to their community on this one.
--type-check is still marked as deprecated and it makes precommit hooks terribly terribly slow to run tsc before.

@kasvtv in case you missed it, TSLint is deprecated now: #4534. You'll want to switch to https://typescript-eslint.io.

I hear your point and agree with the pain point, but at this point your best bet is to switch tools anyway.

Was this page helpful?
0 / 5 - 0 ratings