diff --git a/README.md b/README.md index dca0fb6e..56850745 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ assert(record1.a === 1); assert(record1["a"] === 1); assert(record1 !== record2); assert(record2 === #{ a: 1, c: 3, b: 5 }); +assert(record1?.a === 1); +assert(record1?.d === undefined); +assert(record1?.d ?? 5 === 5); +assert(record1.d?.a === undefined); ``` #### `Tuple` @@ -151,6 +155,8 @@ At runtime, attempting to create a `Record` with a key that is not a `string` or At runtime, it is a `TypeError` to add a value to a `Record` or `Tuple` of any type except the following: `Record`, `Tuple`, `string`, `number`, `symbol`, `boolean`, `bigint`, `undefined`, or `null`. +If you try to use a method definitions as part of a Record, the same behavior is expected, it should fail at runtime (even if we could fail at compile time). + # Equality Instances of `Record` and `Tuple` are deeply immutable, so their equality works like that of other JS primitive value types like `boolean` and `string` instances: @@ -326,6 +332,12 @@ JSON.stringify(#{ a: #[1, 2, 3] }); // '{"a":[1,2,3]}' JSON.stringify(#[true, #{ a: #[1, 2, 3] }]); // '[true,{"a":[1,2,3]}]' ``` +## JSON.parseImmutable + +We propose to add `JSON.parseImmutable` so we can extract a Record/Tuple type out of a JSON string instead of an Object/Array. + +The signature of `JSON.parseImmutable` is identical to `JSON.parse` with the only change being in the return type that is now a Record or a Tuple. + ## `Record` prototype The `Record` prototype is an empty object.