type: intersections & unions don't work together
Closed this issue · 2 comments
fergusean commented
test('intersections with unions', () => {
type PortConfig = { protocol: 'tcp' | 'udp' } | { protocol: 'tls'; tlsCertPath: string; tlsKeyPath: string };
type ServerConfig = PortConfig & {
port: number;
};
const type = typeOf<ServerConfig>();
const serialize = getSerializeFunction(type, serializer.deserializeRegistry);
const test1 = serialize({ protocol: 'tcp', port: 123 });
expect(test1).toEqual({ protocol: 'tcp', port: 123 });
const test2 = serialize({ protocol: 'tls', tlsCertPath: 'a', tlsKeyPath: 'b', port: 456 });
expect(test2).toEqual({ protocol: 'tls', tlsCertPath: 'a', tlsKeyPath: 'b', port: 456 });
const test3 = serialize({ protocol: 'tls', port: 789 });
expect(test3).toEqual({ protocol: 'tls', port: 789 });
const test4 = serialize({ protocol: 'fake', port: 789 });
expect(test4).toEqual({ port: 789 });
// all 4 are "undefined"
});
marcj commented
@fergusean thanks for the report. this should be fixed in 332b26e. problem was that union& object literal intersection didn't expand each union member before, but that's now implemented