Skip to content

Spread operator + unknown key doesn't result in a type error #14706

@brandonwamboldt

Description

@brandonwamboldt

TypeScript Version:

TypeScript 2.2.1

Code

interface TestProps {
  foo: string;
  bar: string;
}

function test(mode: number, vars: TestProps): TestProps {
  switch (mode) {
    case 1:
      return { 
        foo: 'a',
        bar: 'b',
        other: 'c', // This is an error
      };
    case 2:
      return {
        ...vars,
        other: 'c', // This SHOULD be an error
      }
  }

  return {
    foo: 'a',
    bar: 'b',
  }
}

Expected behavior:

The spread operator with an unknown attribute should show a type error.

Actual behavior:

The spread operator with an unknown attribute does not show a type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions