ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).
https://docs.superstructjs.org
MIT License
6.96k stars 223 forks source link

Mask fails on `interface aaa { foo: string; [key: string]: any }` interface with any key. #1208

Open oleg-slapdash opened 8 months ago

oleg-slapdash commented 8 months ago

This code throws an error, while this is a valid typescript code:

const interfaceWithAKnownKey = intersection([
  record(string(), any()),
  object({
    foo: string(),
  }),
]);

// Typescript: No ERROR.
const test: typeof interfaceWithAKnownKey.TYPE = {
  foo: "bar",
  extra: "buzz",
};

// StructError: At path: extra -- Expected a value of type `never`, but received: `"buzz"`
interfaceWithAKnownKey.mask(test);