Problems of checking optional object fields
MaksimLavrenyuk opened this issue · 1 comments
MaksimLavrenyuk commented
It seems that when checking objects with optional fields, unexpected behavior occurs. The objects fit the type, but expectType thinks they don't.
import { expectType } from 'tsd';
type FirstExample = {
example: string | undefined
};
type SecondExample = {
example?: string
};
expectType<FirstExample>({ example: 'first' });
expectType<SecondExample>({ example: 'second' });
The result of the work:
✖ Parameter type FirstExample is declared too wide for argument type { example: string; }.
✖ Parameter type SecondExample is declared too wide for argument type { example: string; }.
In typescript playground you can see that this is a valid type:
MaksimLavrenyuk commented
expectType - Strict type assertions, expectAssignable - t loose type assertion. I get it.