TypeScript
  • Introduction
  • Introduction
    • What is TypeScript?
    • Why TypeScript?
    • Setup
  • Beginner
    • Basic types
      • Primitive types
      • Arrays and tuples
      • Enums
      • Any type
    • Objects
    • Type aliases
    • Interfaces
    • Functions
      • Function signatures
      • Void type
      • Functions as types
    • Union types
    • Type guards
    • Intersection types
    • Nullable types
    • Inference
  • Resources
    • Resources
Powered by GitBook
On this page
  1. Beginner
  2. Basic types

Any type

PreviousEnumsNextObjects

Last updated 6 years ago

The any type allows you to opt-out of type-checking during compilation.

let notSure: any = 13;
notSure = "maybe a string instead";
notSure = false; // OK, guess it's a boolean

The any type is handy if you know some part of the type, but perhaps not all of it. For example, you may have an array but the array has a mix of different types:

const myList: any[] = [13, 'Blue Streak is a film from 1999', false];

Note: using any should be avoided when possible. By opting out of type-checking we lose out on the advantages of having a static type system, .

as discussed earlier