This rule doesn't allow
anytypes to be defined. It aims to keep TypeScript maximally useful. TypeScript has a compiler flag for
--noImplicitAnythat will prevent an
anytype from being implied by the compiler, but doesn't prevent
anyfrom being explicitly used.
The solution to this is not one, but two.
That is, if you use Node.js. There is also one for Deno.
I prefer zod.
import * as z from 'zod' // @ts-ignore const apiKey = z.string().parse(payload.apiKey)
- Always consider a validation library, or defensive programming
Hegel, or Babel with Flow + tcomb, might even work better than TypeScript. (Also, without having to use