The Types You Use Daily, and any

The list is short. string, number, boolean, null, undefined, arrays, and unions of literals.

Then three that are about the type system itself: any, unknown and never.

any switches checking off, and it spreads. Anything derived from an any is also unchecked, so a single any at the top of a chain silences the compiler for everything downstream, which is exactly where you needed it loudest.

Reaching for any to silence an error usually moves the error to runtime rather than removing it.

Try it

Notice the typo: titel. The any version is happy with it.

loading editor…

checking…

Four uses of any, no complaints. One use of unknown, immediately caught. That contrast is the whole argument for preferring unknown.

◈ Graded Types

Write a function called describe that takes a title (a string) and a year (a number) and returns a string of the form "Kindred (1979)". Annotate both parameters. The function must type-check in strict mode.

Checked against the compiler, not against how you wrote it. 2 visible and 2 hidden checks.

loading editor…
real tsc, strict mode

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back