by ghh · 10y ago · 0 comments
That is to introduce a preliminary type definition. Instead of:
const oldVar: any = { field: 1, ... }
function foo(bar: any) { ... }
You can write: declare type OldVarType = any
const oldVar: OldVarType = { field: 1, ... }
function foo(bar: OldVarType) { ... }
This way, you can signal that it's not just any kind of any, but a particular kind of any, which is now trackable in your codebase.When you're ready, you can gradually update the OldVarType declaration and solve the compiler type check warnings from there. Union types [1] can be quite useful then too.
[1] https://www.typescriptlang.org/docs/handbook/advanced-types....
You can ban the `any` type along with lots of other rules. You can also write your own custom rules, or implimnet rulesets by 3rd parties like Microsoft: https://github.com/Microsoft/tslint-microsoft-contrib and ESLint: https://github.com/buzinas/tslint-eslint-rules
" = any"
This would only show types that are aliases of the "any" type. As a side note, the following would create a compiler error ("cannot find name 'any'") because types are metadata and can't be used as program data.
const something = any;