Skip to content

Bug in Pick and Discriminated Unions #28791

Closed
@cliedeman

Description

@cliedeman

TypeScript Version: 3.2.1

Search Terms: Discriminated Unions, Pick, Exclude

interface BaseTextFieldProps {
    name?: string
}

export interface StandardTextFieldProps extends BaseTextFieldProps {
    variant?: 'standard';
}

export interface FilledTextFieldProps extends BaseTextFieldProps {
    variant: 'filled';
}

export type TextFieldProps = StandardTextFieldProps | FilledTextFieldProps;

export type FieldProps = {
    someProps: string
};

export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

export type Props1 = FieldProps & Omit<TextFieldProps, 'name'>

export const func1 = ({...props}: Props1): TextFieldProps => {

    return {
        ...props,
    };
};

export type Props2 = FieldProps & TextFieldProps

export const func2 = ({...props}: Props2): TextFieldProps => {

    return {
        ...props,
    };
};

Expected behavior:
Compiles

Actual behavior:
Errors with incompatible types for variant

Playground Link:

Related Issues:
#27201 (comment)
#28274
but these were related to generics so I could not be sure if this is a duplicate or not

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions