Is assertObjectMatch too type-strict?
If you have two typed objects,
What am I doing wrong here?
actualactual and expectexpect, of the same type, assertObjectMatchassertObjectMatch doesn't let you use the expectexpect object: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<PropertyKey, unknown>'.
// Index signature for type 'string' is missing in type 'FirstLast'.
// casting is ugly:
assertObjectMatch(actual, expected as unknown as Record<PropertyKey, unknown>);
});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<PropertyKey, unknown>'.
// Index signature for type 'string' is missing in type 'FirstLast'.
// casting is ugly:
assertObjectMatch(actual, expected as unknown as Record<PropertyKey, unknown>);
});What am I doing wrong here?
