Using the any type defeats the purpose of using TypeScript.
When any is used, all compiler type checks around that value are ignored.
This rule goes doesn't allow any types to be defined.
It aims to keep TypeScript maximally useful.
TypeScript has a compiler flag for --noImplicitAny that will prevent
an any type from being implied by the compiler, but doesn't prevent
any from being explicitly used.
The following patterns are considered warnings:
const age: any = "seventeen";const ages: any[] = ["seventeen"];const ages: Array<any> = ["seventeen"];function greet(): any {}function greet(): any[] {}function greet(): Array<any> {}function greet(): Array<Array<any>> {}function greet(param: Array<any>): string {}function greet(param: Array<any>): Array<any> {}The following patterns are not warnings:
const age: number = 17;const ages: number[] = [17];const ages: Array<number> = [17];function greet(): string {}function greet(): string[] {}function greet(): Array<string> {}function greet(): Array<Array<string>> {}function greet(param: Array<string>): string {}function greet(param: Array<string>): Array<string> {}If an unknown type or a library without typings is used
and you want to be able to specify any.
- TypeScript any type
- TSLint: no-any