← All notes

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

License: CC-BY-4.0 · 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).

Cite this

Permanent ID: iil:note:3kcvv456

iinventedlight. 2026. "Everyday types in TypeScript." iinventedlight Library, iil:note:3kcvv456, version of 2026-11-03. https://iinventedlight.com/library/notes/typescript-basic-everyday-types/. License: CC-BY-4.0.

@misc{iil_note_3kcvv456,
  author = {{iinventedlight}},
  title = {{Everyday types in TypeScript}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-03},
  url = {https://iinventedlight.com/library/notes/typescript-basic-everyday-types/},
  note = {Permanent ID iil:note:3kcvv456. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-basic-everyday-types.md.