liveBook · Manning

Static typing

As explained in Acing the Frontend Interview

Static type checking is the compiler-time analysis of code to detect violations of declared or inferred type constraints.

Static typing analyzes code at compile time against declared or inferred type constraints. TypeScript adds this system to JavaScript, catching errors early while improving readability, maintainability, autocompletion, navigation, and refactoring. section 3.0 section 3.6

In practical development and interviews, static typing supports:

  • Detecting incorrect values and missing properties before runtime. section 3.6
  • Making APIs and data structures clearer through interfaces, generics, type guards, and declaration files. section 3.12 section 3.9
  • Supporting safer changes with type-aware autocompletion, navigation, and refactoring. section 3.6
  • Enforcing stronger guarantees through type narrowing, assertions, strict compiler settings, and exhaustive checks. section 3.9

Third-party browser APIs

A React component loading the YouTube API can work at runtime while TypeScript reports that Window lacks YT and onYouTubeIframeAPIReady, and that an event parameter is implicitly any. Extending the global Window interface with declaration merging supplies those types and removes the errors. section 3.10

Listing 3.21 Declare the global YT namespace for window.YT and window.onYouTubeIframeAPIReady
declare global { #A
  interface Window { #B
    YT: { #C
      Player: new ( #D
        element: HTMLElement | null,
        config: {
          height: string; #E
          width: string; #F
          videoId: string; #G
          events: {
            onReady: (event: { target: { playVideo: () => void } }) => void; #H
          };
          playerVars: { #I
            autoplay: number; #J
            mute: number; #K
          };
        }
      ) => void;
    };
    onYouTubeIframeAPIReady?: () => void;   #L
  }
}

Inspect the declaration-merging example, including the typed YT player constructor, configuration fields, callback event, and optional global callback. section 3.10

How Acing the Frontend Interview covers it

How deep it goes
Covers compile-time checking, narrowing, assertions, strictness, declaration files, and global augmentation rather than runtime behavior.
Examples
Uses a React YouTube API integration, Window augmentation, typed callbacks, and incorrect state assignments as concrete examples.
What you can do after
Apply it via TypeScript to catch errors early, type JavaScript APIs, configure strictness, and refactor code more safely.
How it connects
Connects TypeScript with JavaScript interoperability, interfaces, generics, type guards, declaration files, compiler configuration, and third-party APIs.

Also explained in

Compare how 13 books explain static typing →

Related concepts

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