We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Any

Okay, so we know TypeScript's purpose is to add static types to JavaScript, and we know all JavaScript is valid TypeScript.

In practical terms, what that means is when you compile plain JavaScript code using tsc, your codebase is full of any types.

The any type is exactly what it sounds like - a type that can be anything. The purpose of types, really, is to narrow down the possible values that a variable can hold. From that perspective, any is the most useless type because it doesn't narrow anything down at all! But it's important because it allows you to opt out of type-checking for a variable.

The any type is super useful when you migrate an existing JavaScript codebase to TypeScript. The (very simplified) process is:

  1. Change file extensions from .js to .ts
  2. Get tsc running without errors (often works out of the box, due to any)
  3. Slowly over time, replace any's with more specific types

Boot.dev's front-end used to be JavaScript! We went through this exact process a couple of years ago getting it all converted to TypeScript and slowly purging the any's.

Assignment

While vibe migrating a JavaScript file to TypeScript, a bunch of any's were inserted into the codebase.

Update the constants from any to their proper types (by using inference).