Is assertObjectMatch too type-strict?
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
If you have two typed objects, `actual` and `expect`, of the same type, `assertObjectMatch` doesn't let you use the expect object:
```ts
import { assertObjectMatch } from '@std/assert';
interface FirstLast {
first: string
last: string
}
Deno.test('assertObjectMatch', () => {
const expected: FirstLast = {
first: 'John',
last: 'Doe',
};
const actual = expected;
// passes
assertObjectMatch(actual, {
first: 'John',
last: 'Doe',
});
// fails because `expected` is too typed now?
assertObjectMatch(actual, expected);
// Argument of type 'FirstLast' is not assignable to parameter of type 'Record'.
// Index signature for type 'string' is missing in type 'FirstLast'.
// casting is ugly:
assertObjectMatch(actual, expected as unknown as Record);
});
```
**Describe the solution you'd like**
No error when passing expected objects whose type matches that of the actual object.
**Describe alternatives you've considered**
[Asked on Discord](https://discord.com/channels/684898665143206084/1330481223507640390/1330481223507640390) ~a week ago, no replies yet.
Contributor guide
Assessment
This issue has not been assessed yet.