TypeScript Schema Decoding: Incorrect Type Masks Other Errors

Hello,
I found something interesting. I don't know if it can be considered a bug, or if it can only work this way.
When decoding a Schema, if a wrongly typed property is passed as parameter, typescript will only flag the wrognly typed property error and ignore other things such as missing properties, or extra properties passed.

For instance, given this schema:
const FooSchema = Struct({
  bar: String,
  buz: String,
});


// Will flag `Property buz is missing in type { bar: string; }` as intended
yield* decode(FooSchema)({
  bar: "foo",
});

// Will flag `TS2353: Object literal may only specify known propertie` as intended
yield* decode(FooSchema)({
  bar: "foo",
  buz: "bar",
  doesNotExist: "whatever"
});

// Will flag `TS2322: Type number is not assignable to type string` on `bar`
// totally omitting the two errors above
yield* decode(FooSchema)({
  doesNotExist: "whatever",
  bar: 5,
});


Which to me is problematic because if you have :
yield* decode(FooSchema)({
  doesNotExist: 5,
  // @ts-expect-error for whatever reason
  bar: 5,
});

then no error is flagged at all even though there's an exta property + a missing one.
Was this page helpful?