opened
reinismu
username_0
Added `.exact()` for `Record`. It allows to check that incoming object doesn't have additional fields.

Close #41 

First I tried to create `{ strict: true }`, but `validate`, `check` etc. are shared between multiple Runtypes and they don't really need that setting.
Exact record support
issue
created
jraoult
username_1
@username_0 I'm excited about this. Have you heard from @pelotom regarding this PR?
comment
created
reinismu
username_0
Nop :/ 

I made my own build so I could use this change + Omit
```
"dependencies": {
    "runtypes": "github:username_0/runtypes#with-pick-omit"
  },
```
If you are interested
comment
created
bayareacoder
username_2
This doesn't work for me if you have a record with optional properties:
const Test = Record({...}).And({...}).exact();
Seems a common use case to make sure that no extra keys, besides the optional ones, are present.

`Property 'exact' does not exist on type 'Intersect2<Record`
comment
created
jraoult
username_1
@username_0 cheers, I ended up moving to [zod](https://github.com/colinhacks/zod) anyway. It wasn't too hard after all. I feel this project is sadly losing momentum and zod provide strict check by default out of the box and some other nice goodies API wise.
comment
created
bayareacoder
username_2
@username_0 You closed this issue but does it work for an object with both required and optional keys, to make sure there are either no required keys missing, or no additional keys, beyond the optional ones, specified? I don't see that case in your tests.
I believe this is a very common use case to eg test an API response.
We use this library and found a way to check for this that works, but is not elegant:

```
const allowedKeys = ['requiredKey1', ..., 'requiredKeyM', 'optionalKey1', ..., 'optionalKeyN'];
const RTtype = Record({
requiredKey1: ...
...
requiredKeyM: ...
})
.And(Partial({
optionalKey1: ...
...
optionalKeyN: ...
})
.And(Dictionary(Unknown, allowedKeys));
```
This will check that:
- all required keys are present and of correct type
- optional keys, if present, are of the correct type
- no additional keys are present.

Basically I don't think an exact spec on any union type works, since it's not the same as the union of the exact types...
comment
created
reinismu
username_0
@username_1 Thanks! It seems promising  

@username_2 From use of it I have noticed few edge cases where it doesn't work. One of them is when trying to use `Or`
comment