[TypeScript] Increase TypeScript's type safety with noImplicitAny

TypeScript tries to infer as much about your code as it can.

But sometimes there really is not enough context for it to infer reliably. If it tried to do such inference it would potentially result in more nuisance than help. So instead it infers the type any. This type can catch people off guard as it provides very little type safety. Fortunately TypeScript has a flag to make it easier to catch such unsafe code at development time.

 

// tsconfig.json

"noImplicitAny": true,

 

And also the annoying index type error:

const values = Object.keys(foo).map(key => foo[key])

We can set to solve this error message:

"suppressImplicitAnyIndexErrors": true,

 

posted @ 2017-02-23 04:20  Zhentiw  阅读(273)  评论(0编辑  收藏  举报