funtypes icon indicating copy to clipboard operation
funtypes copied to clipboard

Exact / Sealed / Closed objects

Open ForbesLindesay opened this issue 5 years ago • 2 comments

There is currently no way to disallow additional properties on records. The closest you could get would be to Intersect the Record with a Dictionary that specifies the allowed fields.

Proposed API:

interface Record<T> {
  // ...existing props and methods...
  asExact(): this;
}

ForbesLindesay avatar Sep 06 '20 15:09 ForbesLindesay

https://github.com/pelotom/runtypes/pull/162 looks like a pretty good start. I'm inclined not to attempt to make it a generic parameter, since it doesn't really affect the TypeScript type of the parsed value.

(Would also resolve https://github.com/pelotom/runtypes/issues/169 and https://github.com/pelotom/runtypes/issues/41)

ForbesLindesay avatar Sep 11 '20 02:09 ForbesLindesay

Added in #56

ForbesLindesay avatar Mar 18 '22 13:03 ForbesLindesay