Skip to content

Commit

Permalink
Improve Excess Properties explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Else committed Feb 26, 2020
1 parent 801f994 commit f8577ce
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions README.md
Expand Up @@ -169,6 +169,12 @@ interface Name {

## Excess Properties (⛔ Inconsistency)

TypeScript is a **structurally** typed language. This means that to create a `Dog` you don’t need to explicitly extend the `Dog` interface. Instead any object with a `breed` property that is of type `string` can be used as a `Dog` (see example below).

Engineers **can’t** just think of interfaces as “objects that have exactly a set of properties” or “objects that have at least a set of properties”.

> Inline object arguments receive an additional level of validation that doesn’t apply when they’re passed as variables.
```ts
interface Dog {
breed: string;
Expand All @@ -192,17 +198,6 @@ printDog({
// excess properties are NOT OK!! Argument of type '{ breed: string; age: number; }' is not assignable..
```

> TypeScript is a **structurally** typed language. This means that to
> create a `Dog` you don’t need to explicitly extend the `Dog`
> interface. Instead any object with a `breed` property that is of type
> `string` can be used as a `Dog`.
>
> Engineers can’t just think of interfaces as “objects that have exactly
> a set of properties” or “objects that have at least a set of
> properties”. They have to consider that **inline** object arguments
> receive an **additional level of validation** that doesn’t apply when
> they’re **passed as variables**.
# Mapped Types - Getting Types from Data

## Using `typeof` / `keyof`
Expand Down

0 comments on commit f8577ce

Please sign in to comment.