Skip to content

Remaining properties of a generic type can't be accessed after using spread on it #28821

Closed
@que-etc

Description

@que-etc

TypeScript Version: 3.3.0-dev.20181201

Search Terms:

  • generic
  • pick
  • exclude
  • spread

Code

type TargetProps = {
    foo: string,
    bar: string
};

const modifier = <T extends TargetProps>(targetProps: T) => {
    let {bar, ...rest} = targetProps;

    let result: typeof rest & {bar: string}

    // 'foo' doesn't exist 
    rest.foo;

    // Type 'Pick<T, Exclude<keyof T, "bar">> & { bar: string; }' is not assignable to type 'T'.
    let combined: T = result;
};

Expected behavior:
Rest properties of an object, which has a generic type, should be accessible after the spread operator was applied.

Actual behavior:
None of the properties described in the base TargetProps type can be accessed.

Playground Link: link

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional types

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions