---
title: "Everyday types in TypeScript"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/typescript-basic-everyday-types.md
source_license: "CC BY 4.0 (TypeScript-Website docs); restated in our own words"
attribution: "Summary by iinventedlight (AI-assisted). Sources: TypeScript (Microsoft), The Basics, CC BY 4.0 (TypeScript-Website docs); TypeScript (Microsoft), Everyday Types, CC BY 4.0 (TypeScript-Website docs)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-03
status: published
checked_on: 2026-11-03
as_of: 2026-11-03
confidence: medium
untested: "tsc was not installed or run; sample programs were not type-checked; only the fetched handbook pages were read."
category: coding-references
topic_area: "TypeScript basics"
tags: typescript, types, compiler, handbook
sources:
  - id: S1
    title: "The Basics"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
    accessed: 2026-11-03
    license: "CC BY 4.0 (TypeScript-Website docs)"
  - id: S2
    title: "Everyday Types"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
    accessed: 2026-11-03
    license: "CC BY 4.0 (TypeScript-Website docs)"
---
# Everyday types in TypeScript

## Summary
TypeScript checks JavaScript before it runs, then tsc erases the extra syntax and emits plain JavaScript. Annotations describe values. They do not change runtime behavior.

## Check, then emit
Calling a string throws. Reading a missing property often yields undefined. The checker flags both, plus typos and impossible comparisons, and the same facts drive editor completions.

Install the compiler from the typescript package. `tsc hello.ts` with no type errors prints nothing and still writes hello.js. By default tsc emits even after errors. `--noEmitOnError` leaves the output unchanged. Write types after the name. Skip an annotation when the initializer already implies the type. Annotations are erased and do not change runtime behavior. The default compile target is ES5, which may rewrite a template string as concatenation. `--target es2015` keeps newer syntax.

Defaults are loose: types are optional, and null may be assigned anywhere. Turn on the strict flag, or `"strict": true`, for a new codebase. noImplicitAny errors when a missing type becomes any. strictNullChecks makes you handle null and undefined.

## Types you write most often
Use lowercase string, number, and boolean. The capitalized names are different built-ins. There is no separate int type. `number[]` and `Array<number>` are the same array type. `[number]` is a tuple. any turns checking off. Treat it as an escape hatch.

An object type lists properties. `?` marks one optional; test for undefined before use. A union (`A | B`) accepts any member, but you may only use operations every member supports. Narrow with typeof or Array.isArray.

A type alias names any type. An interface names an object type and can be reopened to add fields; a type alias cannot. Start with interface. Checking is structural: the shape matters. An `as` assertion is erased and does not throw if wrong. const can keep a literal type; let widens. `as const` keeps literals on an object. A postfix `!` asserts non-null and does nothing at runtime. Enums are emitted into JavaScript. Wait to use them until you mean to.

## Claims
- id: C1
  claim: A static type system predicts what code is expected to do before it runs, and TypeScript reports problems before you execute the program.
  source: S1
  evidence: "The alternative is to use a static type system to make predictions about what the code is expected to do before it runs."
- id: C2
  claim: Running tsc on a TypeScript file emits a plain JavaScript file next to the source when type-checking succeeds.
  source: S1
  evidence: "That's the output from our hello.ts file after tsc compiles or transforms it into a plain JavaScript file."
- id: C3
  claim: Type annotations are erased by the compiler and do not change how the program behaves at runtime.
  source: S1
  evidence: "Type annotations never change the runtime behavior of your program."
- id: C4
  claim: The usual primitive type names to write are string, number, and boolean, not the capitalized built-in names.
  source: S2
  evidence: "Always use string , number , or boolean for types."
- id: C5
  claim: A union type is built from two or more types and stands for a value that may be any one of those members.
  source: S2
  evidence: "A union type is a type formed from two or more other types, representing values that may be any one of those types."
- id: C6
  claim: An interface is another way to name an object type, and TypeScript checks the structure of the value rather than a separate nominal brand.
  source: S2
  evidence: "An interface declaration is another way to name an object type"
