Skip to content

Union freshness is not removed when required #19226

Closed
@weswigham

Description

@weswigham

TypeScript Version: 2.6.0-dev.201xxxxx

Code

import * as React from "react";
import { SFC } from "react";


type CommonProps = { common: string };
type Props = CommonProps &
    ({ type: 'foo' } | { type: 'bar'; message: string });

const Button: SFC<Props> = (props) => null;

const OtherButton1: SFC<Props> = (props) => {
    const props2 = {...props};
    return React.createElement(Button, props2); // `props2` should be fine, just like `props` is
};

Expected behavior:
No errors

Actual behavior:

test.tsx(13,40): error TS2345: Argument of type '{ common: string; type: "foo"; children?: ReactNode; } | { common: string; type: "bar"; message: ...'
is not assignable to parameter of type '(Attributes & CommonProps & { type: "foo"; }) | (Attributes & CommonProps & { type: "bar"; messag...'.
  Type '{ common: string; type: "foo"; children?: ReactNode; }' is not assignable to type '(Attributes & CommonProps & { type: "foo"; }) | (Attributes
& CommonProps & { type: "bar"; messag...'.
    Object literal may only specify known properties, and 'children' does not exist in type 'Attributes & CommonProps & { type: "foo"; }'.

Found when revisiting some test code for something else.

cc @mhegazy @sandersn

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions