Type aliases to `any`

any solves any problem


As you know, any considered harmful in TypeScript. I do believe it’s better to avoid it, and especially after unknown was introduced to replace any in lots of cases. To discourage developers from using it, I can even imagine no-any rule turned on as a warning, but I don’t think deprecating any should be a goal.

Having a number of dependencies, it might be problematic to integrate all the third-party code without using any. Sometimes, when you upgrade a single package, some of its’ types rely on other package’s types, so you have to add a sprinkle of any. Or, pretty commonly, every TypeScript upgrade brings a handful of new errors across whole codebase. And if you don’t have a full picture or even authority to make substantial changes in someone else’s code, at times you have to suppress these errors with another splash of any. Thus, maintaining zero-any codebase seems to me excessively and unduly time consuming.

But we still want to discourage people from using it, and that’s where type aliases to any became handy:

/** */
type temporaryAny = any;

temporaryAny solves refactoring problems mentioned above by not using any and simplifying spotting refactoring-only any.

Once you see the benefits, you realise there is nothing that stops you from annotating every non-semantic any with temporaryAnyUntillCertainProblemSolved:

 * Type alias for string types that have to be narrowed to literal types
type temporaryString = string;

 * Type alias for number types that have to be narrowed to literal types
 * https://github.com/Microsoft/TypeScript/issues/15480
type temporaryNumber = number;

 * Used for situations when conditional types (for example `ReturnValue<>`) should be used.
type temporaryAnyUntilTypescript2_8 = temporaryAny;

And even seemingly too verbose:

 * For generic type `T`:
 * ```
 * const bar: T["bar"] // string | null | undefined
 * if (bar) {
 *  bar // is still `string | null | undefined`
 * }
 * ```
 * https://github.com/Microsoft/TypeScript/issues/22214
type temporaryAnyWhileTypeGuardsNotWorkingForIndexedTypesWithGenerics = temporaryAny;

Every time I type any I wonder if it’s an any or temporary any.