Because assertions are written fluently, error messages can sometimes appear to be describing the 'expected' type rather than the 'actual' type.
For .toEqualTypeOf / .toMatchTypeOf:
If you see a message like Type 'string' is not assignable to type '"Expected: string, Actual: number"', do not take it literally. Look at the property name and the human-readable string inside the quotes. It is telling you: Expected: string, Actual: number.
For .toBe... methods:
These fail by resolving to a non-callable type. An error like Type 'ExpectString<number>' has no call signatures means you asserted a number should be a string.
Best Practice:
To get the clearest error messages, use type arguments instead of concrete objects whenever possible:
- Better:
expectTypeOf({a: 1}).toEqualTypeOf<{a: string}>() - Worse:
expectTypeOf({a: 1}).toEqualTypeOf({a: ''})
If you must compare two concrete values, use typeof:
expectTypeOf(one).toEqualTypeOf<typeof two>()