Skip to content

Type inference corner case in combination of object spread with destructuring #12532

Closed
@Jessidhia

Description

@Jessidhia

TypeScript Version: 2.2.0-dev.20161127

Code

declare var keyPrototype: any
declare function getKeyData(): Promise<{ key: any }>

async function getKey () {
  const { key } = {
    key: {
      ...keyPrototype
    },
    ...await getKeyData()
  }
  return key
}

Expected behavior:

Code to typecheck. The resulting key const should be a shallow copy of keyPrototype, with certain keys overridden by the result of getKeyData.

Actual behavior:

Error on the key declaration inside const { key }: "Initializer provides no value for this binding element and the binding element has no default value", despite the RHS being guaranteed to always have a key key.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions