Skip to content

Destructure and spread on generics not typing #33579

Closed
@saulshanabrook

Description

@saulshanabrook

TypeScript Version: 3.7.0-dev.20190924

Search Terms: destructure spread generic

Code

function test<T extends {key: number}>({key, ...rest}: T): T {
  return {key: 10, ...rest}
}

Expected behavior:

No type errors

Actual behavior:

Type '{ key: number; } & Pick<T, Exclude<keyof T, "key">>' is not assignable to type 'T'.
  '{ key: number; } & Pick<T, Exclude<keyof T, "key">>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{ key: number; }'.

Playground Link: https://www.typescriptlang.org/play/index.html?ts=Nightly#code/GYVwdgxgLglg9mABFApgZygHgCqJQD1TABM1EBvAaxQE8AuRMEAWwCMUAnAXwD4AKKrQA0iAHTiO6KFwbYAlLIoBYAFCJEkqCA5JB9RAEYADCPGjJGLqq5A

Related Issues: #26412 #10727 #28234 #28312 #18552

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions