Skip to content

withDefaults merge object union #10594

Closed
Closed
@th1m0

Description

@th1m0

Vue version

3.4.21

Link to minimal reproduction

play.vuejs.org

Steps to reproduce

withDefaults(
  defineProps<
    {
      def: string
    } & (
      | {
          type: 'hello'
          results: string
        }
      | {
          type: 'world'
          results: number
        }
    )
  >(),
  {
    def: 'default value!',
  }
)

What is expected?

Expected type from this would be:

type ExpectedType = {
    readonly def: string;
    readonly type: 'hello';
    readonly results: string;
} | {
    readonly def: string;
    readonly type: 'world';
    readonly results: number;
}

What is actually happening?

type actualType = {
    readonly type: "hello" | "world";
    readonly results: string | number;
    readonly def: string;
}

System Info

No response

Any additional comments?

The problem is with Typescripts utility type Omit. See: microsoft/TypeScript#54451 and microsoft/TypeScript#53169

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions