1. 11

  2. 3

    Nicely done article that clearly explains why an example that seems inconsistent in TypeScript is an explicit choice that is consistently applied.

    If I understand correctly, arguments/variables that undergo type inference are allowed to have excess properties.

    const dog = { ... }; // <- No type, so the type is inferred

    Variables that do have explicit types are not allowed to have access properties.

    const dog: Dog = { ... }; // <- Explicitly has a type

    And providing a value (as opposed to a variable) as an argument is the same as opting-in to the argument’s type.

    bark({ name: 'rex' }); // <- No type inference

    Pretty sure I did read this in Typing Objects in Javascript, by Axel Rauschmayer, a couple days ago. But this made it really sink in.