Skip to content

Commit

Permalink
fix the summary, expand the motiviation section
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbarabash committed Aug 4, 2024
1 parent 0253574 commit 60c30d8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions docs/rfcs/0002-exact-object-type.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Summary

Exact object types will prevent this issue by not allowing the assignment of
any object with extra fields to a variable that's an exact object.
Exact object are not allowed to have extra properties that aren't present in
their inferred types.

# Motivation

Expand All @@ -15,6 +15,22 @@ let pointAndFlag = { x: 5, y: 10, flag: true };
let point: Point = pointAndFlag; // allowed with inexect object types
```

Having extra properties in an object can also lead to objects ending up with
the incorrect values in them.

```ts
type Point = { x: number; y: number }; // current, inexact object type

let pointAndFlag1 = { x: 5, y: 10, flag: true };
let point: Point = pointAndFlag1; // allowed with inexect object types

type PointAndFlag = { x: number; y: number; flag?: string };
let pointAndFlag2: PointAndFlag = point;
```

`pointAndFlag2.flag` is typed as an optional `string`, but it contains a `boolean`
value.

# Explanation

## Syntax
Expand Down

0 comments on commit 60c30d8

Please sign in to comment.