Open
Description
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 return
s 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