有没有办法让打字稿编译器在显式使用 "any" 类型时抛出错误?

Is there a way for the typescript compiler to throw an error when using the "any" type explicitly?

我正在尝试使用 TS 使我的代码尽可能严格。有没有办法让下面的声明使用“any”作为类型来抛出错误,因为它应该是“string”类型?

const foo: any = "bar"

您可以使用 tslint/eslint 规则来阻止它。在此处找到一些文档 https://palantir.github.io/tslint/rules/no-any/