Weak types

A weak type is an object literal type in which all properties are optional:

interface User {    name?: string;    age?: number;}

TypeScript allows us to add a value with some or all the properties defined in the weak type, but it doesn't allow us to assign properties that are not part of the weak type:

let user1: User  = { name: "Remo", age: 28 }; // OKlet user2: User = { firstName: "Remo", yearBorn: 28 }; // Error

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.