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"
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
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.},
}
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.