Skip to content

Conditional spread results in weird union type, with duplicates #41386

Description

interfaceAnimal{name: string;kind: string;age: number;location: string;owner: object;}functionclonePet(pet: Animal,fullCopy?: boolean){return{name: pet.name,kind: pet.kind,
...(fullCopy&&pet),}}

Expected: clonePet returns type { name: string, kind: string, age?: number, location?: string, owner?: object }

Actual: clonePet returns the following type:

{
name: string;
kind: string;
} | {
name: string;
kind: string;
} | {
name: string;
kind: string;
age: number;
location: string;
owner: object;
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions