Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type: intersections & unions don't work together #556

Closed
fergusean opened this issue Mar 5, 2024 · 2 comments
Closed

type: intersections & unions don't work together #556

fergusean opened this issue Mar 5, 2024 · 2 comments

Comments

@fergusean
Copy link
Contributor

fergusean commented Mar 5, 2024

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 added a commit that referenced this issue Mar 12, 2024
@marcj
Copy link
Member

marcj commented Mar 12, 2024

@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

@marcj marcj closed this as completed Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants