Skip to content

Object.assign does not understand union typesΒ #64677

Description

πŸ”Ž Search Terms

Object.assign, union

πŸ•— Version & Regression Information

  • I have only tried this in version 6.0.3

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBKkPrAgZ2A80C8UBEATA9gLbZQA+OYATvgB4jYDcAUAJYB2ilAZgIYDG0RCjgAbFsIKEoEGoja4kUAIKVKPEAB4UldgHMA2gF0AfFADeTKFahsehCAC4o2vc2sx0T2BATJU35gBfJiY+fDYUKB5VKCwAeQAjACsIPmAAOh4kJBZdNgAKS2sjABoiqwt3d1t7J2wkImgXNl1sMqrrbzqqWnpyqGCASgYgA

πŸ’» Code

type type_test_type = "dom" | "proxy";
interface test_list_dom extends Array<string[]> {
    name: string;
    type: type_test_type;
}

const arr = Object.assign(
    [],
    {
        name: "some string",
        type: "proxy"
    }
);

πŸ™ Actual behavior

Type 'string' is not assignable to type 'type_test_type'.

πŸ™‚ Expected behavior

No issue.

Additional information about the issue

Yes, I can easily suppress the error by using: type: "proxy" as type_test_type but in all other cases of union types a matching value is recognized as a member of the union.

The provided code sample is simplified from the actual code in my repository generating the issue. I cannot generate this issue from either code in the TypeScript Playground.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions