Item 83: Don't Consider Migration Complete Until You Enable noImplicitAny
要点
- Don't consider your TypeScript migration done until you adopt
noImplicitAny
. Loose type checking can mask real mistakes in type declarations. - Fix type errors gradually before enforcing
noImplicitAny
. Give your team a chance to get comfortable with TypeScript before adopting stricter checks.
正文
ts
class Chart {
indices: any
// ...
}
ts
class Chart {
indices: number[]
// ...
}
ts
getRanges() {
for (const r of this.indices) {
const low = r[0];
// ^? const low: any
const high = r[1];
// ^? const high: any
// ...
}
}
ts
getRanges() {
for (const r of this.indices) {
const low = r[0];
// ~~~~ Element implicitly has an 'any' type because
// type 'Number' has no index signature
const high = r[1];
// ~~~~ Element implicitly has an 'any' type because
// type 'Number' has no index signature
// ...
}
}