Why typescript with strictNullChecks=true doesn't complain when accessing the property of an object?

56 views Asked by At

Probably there is something I don't understand. In this code I expect typescript to emit a warning for the line page.name = 'foo'; because page can be null?

export interface Page {
  id: string;
  name: string;
}

const pages: { [id: string]: Page } = {};

function f(id: string) {
  let page = pages[id];
  page.name = 'foo';
}

Can someone explain me? Thanks!

playground

0

There are 0 answers