Skip to content

Intersection causes incorrect type compatabilityΒ #48720

Open
@webstrand

Description

@webstrand

Bug Report

πŸ”Ž Search Terms

intersection assignability omit compatability

πŸ•— Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type APIApplicationCommandSubcommandGroupOption = {
    options?: APIApplicationCommandSubcommandOption[];
}

type CommandSubcommandGroupOption = Omit<APIApplicationCommandSubcommandGroupOption, 'options'> & { // <-- so is this one
  options?: CommandSubcommandOption[]
}

type CommandSubcommandOption = { otherProps: unknown } & { // <-- this intersection is apparently critical
  options?: unknown[]
}

interface APIApplicationCommandSubcommandOption {
    options?: { foo: string }[];
    otherProps: unknown;
}

function transformSubcommandGroupOption1(option: CommandSubcommandGroupOption): APIApplicationCommandSubcommandGroupOption {
  return option; // no error, but there _should_ be an error here.
}

function transformSubcommandGroupOption2(option: CommandSubcommandGroupOption): APIApplicationCommandSubcommandGroupOption {
  return { ...option }; // error in 3.9.7
}

πŸ™ Actual behavior

The return option does not produce an error and the return { ...option } does produce an error.

πŸ™‚ Expected behavior

Both returns should behave the same. Ideally, both should produce an error because CommandSubcommandGroupOption is incompatible with APIApplicationCommandSubcommandGroupOption.

From help thread on Discord: https://discord.com/channels/508357248330760243/964236133330460772

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosNeeds InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions