diff --git a/IDEAS.md b/IDEAS.md index e9f1bb2c..d663ddbe 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -20,7 +20,6 @@ let trimContract: S.contract string> = S.contract(s => { ## v9 -- deepStrict for js/ts - Update documentation: - Add Enums section to js docs diff --git a/packages/tests/src/core/S_test.ts b/packages/tests/src/core/S_test.ts index a570892c..08ca063e 100644 --- a/packages/tests/src/core/S_test.ts +++ b/packages/tests/src/core/S_test.ts @@ -916,6 +916,44 @@ test("Fails to parse strict object with exccess fields", (t) => { ); }); +test("Fails to parse deep strict object with exccess fields", (t) => { + const schema = S.deepStrict( + S.schema({ + foo: { + a: S.string, + }, + }) + ); + + t.throws( + () => { + const value = S.parseOrThrow( + { + foo: { + a: "bar", + b: true, + }, + }, + schema + ); + expectType< + SchemaEqual< + typeof schema, + { + foo: { + a: string; + }; + } + > + >(true); + }, + { + name: "RescriptSchemaError", + message: `Failed parsing at ["foo"]. Reason: Encountered disallowed excess key "b" on an object`, + } + ); +}); + test("Fails to parse strict object with exccess fields which created using global config override", (t) => { S.setGlobalConfig({ defaultUnknownKeys: "Strict", diff --git a/src/S.d.ts b/src/S.d.ts index 5278a9c0..d84f0fc2 100644 --- a/src/S.d.ts +++ b/src/S.d.ts @@ -230,9 +230,15 @@ export function object>( export function strip>( schema: Schema ): Schema; +export function deepStrip>( + schema: Schema +): Schema; export function strict>( schema: Schema ): Schema; +export function deepStrict>( + schema: Schema +): Schema; export function merge( schema1: Schema>, diff --git a/src/S.js b/src/S.js index dc54ddd5..42c8915f 100644 --- a/src/S.js +++ b/src/S.js @@ -35,7 +35,9 @@ export const assertOrThrow = S.assertOrThrow; export const recursive = S.recursive; export const merge = S.js_merge; export const strict = S.strict; +export const deepStrict = S.deepStrict; export const strip = S.strip; +export const deepStrip = S.deepStrip; export const custom = S.js_custom; export const tuple = S.tuple; export const asyncParserRefine = S.js_asyncParserRefine;