liveBook · Manning

Static typing

As explained in Pro Angular 16

Static typing is a language feature in which declared or inferred types are checked before program execution and incompatible assignments can produce compiler errors.

Static typing checks declared or inferred types before a program runs, helping catch incompatible assignments during compilation. TypeScript adds static types to JavaScript, then compiles TypeScript features into browser-executable JavaScript. section 2.3.1 section 3.4

A practical TypeScript data model uses types while retaining familiar JavaScript structure:

  • Declare a task as a string and its completion state as a boolean. section 2.3.1
  • Represent a collection with a TodoItem[] array and expose it as readonly TodoItem[]. section 2.3.1
  • Use compilation to remove TypeScript-specific features before browser execution. section 2.3.1

Typed to-do item

export class TodoItem {\n constructor(public task: string, public complete: boolean = false) {}\n}\n\nThe constructor requires a string task and defaults complete to false, making the model's expected data explicit. section 2.3.1

Listing 2.7. The contents of the todoItem.ts file in the src/app folder
export class TodoItem {
 
  constructor(public task: string, public complete: boolean = false) {
      // no statements required
  }
}

Inspect the complete TodoItem implementation, including its typed constructor parameters and default completion state. section 2.3.1

How Pro Angular 16 covers it

How deep it goes
Explains the TypeScript-to-JavaScript compilation relationship and demonstrates typed model fields, but defers comprehensive language coverage.
Examples
Demonstrates typed TodoItem and TodoList classes with string, boolean, array, and readonly collection types.
What it assumes
Starts with the TypeScript and JavaScript basics needed for Angular development rather than assuming comprehensive language knowledge.
What you can do after
Build it from scratch by defining simple TypeScript data models that compile into browser-executable JavaScript.
How it connects
Connects static typing with TypeScript, JavaScript, Angular, data models, classes, constructors, modules, and compilation.

Also explained in

Compare how 12 books explain static typing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.