Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

[Rule Suggestion] Add no-implicit-any as a linter rule #4215

@fnune

Description

@fnune

Rule Suggestion

Hello there, I've been trying to hack around with tslint to make a PR but before I invest any more time I'd like to contrast the idea with the repo maintainers.

Is your rule for a general problem or is it specific to your development style?

It tackles a general problem: in big codebases that have been moved from JavaScript to TypeScript, turning the noImplicitAny compiler flag on could mean a pretty big refactor, and most developers would be very happy to have a way to gradually adopt the compiler flag for new files, or in a way that doesn't break compilation.

What does your suggested rule do?

Activating this rule would make the linter behave exactly like the compiler when anything implicitly has an any type. Currently with the compiler, it looks like this:

image

The goal is to be able to check this with tslint and be able to set it as a warning.

An idea for an autofix possibility

I haven't thought of this too well, but a possible way to autofix these issues would be to explicitly add the any type hint. Probably not the best idea.

List several examples where your rule could be used

Developers about in the internet have adopted two workarounds that I know of:

  • Split their tsconfig.json using the extends field (docs here) so that their editors use a config with noImplicitAny activated but their build scripts use one without it.
  • Add @ts-nocheck plus the error numbers that are caused by activating noImplicitAny as a compiler flag, and subsequently not adding the magic comment on new files so the rule is checked for new development. This has risk of becoming a regression if any of the rules can also be triggered by a different compiler flag being activated, or by the default TS compiler.

In both of these cases developers would benefit from being able to activate no-implicit-any as a tslint rule in order to be able to adapt it gradually.

Additional context

Related discussions:
microsoft/TypeScript#18540
microsoft/TypeScript#8855
microsoft/TypeScript#11051

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions