JavaScript logoJavaScript/
JS-0486

Avoid `mixed` type annotationsJS-0486

Minor severityMinor
Anti-pattern categoryAnti-pattern

The mixed typed annotations should preferably not be used. These types are not strict enough and could often be made more specific. We recommend using Primitive Types, Union Types, or any.

There are multiple ways to fix the issue:

  • Use Primitive types i.e., Booleans,Strings, Numbers,null,undefined (void in Flow types), Symbols (new in ECMAScript 2015)
  • Union types are any number of types which are joined by a vertical bar |.
  • If you want a way to opt-out of using the type checker, any is the way to do it. Using any is completely unsafe, and should be avoided whenever possible.

Bad Practice

function noMixedFunction(thing): mixed {}

function noMixedFunction(thing): Promise<mixed> {}

function noMixedFunction(thing): Promise<Promise<mixed>> {}
function noMixedFunction(thing): string {}

function noMixedFunction(thing): Promise<string> {}

function noMixedFunction(thing): Promise<Promise<string>> {}

References