Skip to content

Index signature incorrectly includes undefined when computed property name and spread are both present #39278

@RyanCavanaugh

Description

@RyanCavanaugh

TypeScript Version: 4.0.0-beta

Search Terms: index signature spread undefined computed

Code

declare const m: { [k: string]: string };
const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };

Expected behavior: No error (3.9.3)

Actual behavior: Error

a.ts:2:7 - error TS2322: Type '{ [x: string]: string | undefined; }' is not assignable to type '{ [k: string]: string; }'.
  Index signatures are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

2 const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" };
        ~

Playground Link: linky

Related Issues: no

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions