Skip to content
本页内容

In some cases where no type annotations are present, TypeScript will fall back to a type of any for a variable when it cannot infer the type.

This can cause some errors to be missed, for example:

ts
// @noImplicitAny: false
function fn(s) {
  // No error?
  console.log(s.subtr(3));
}
fn(42);
// @noImplicitAny: false
function fn(s) {
  // No error?
  console.log(s.subtr(3));
}
fn(42);

Turning on noImplicitAny however TypeScript will issue an error whenever it would have inferred any:

ts
// @errors: 7006
function fn(s) {
  console.log(s.subtr(3));
}
// @errors: 7006
function fn(s) {
  console.log(s.subtr(3));
}