Skip to content

Bug: strictNullChecks + object spread + computed key #37103

Open
@bogdan

Description

@bogdan

TypeScript Version: 3.8.2

Search Terms:

  • strictNullChecks
  • object spread
  • computed key

Code

const b = { a: 'hello' };
const key: string = 'hello';
const a: Record<string, string> = { ...b, [key]: undefined };

Expected behavior:

Type check fails

Actual behavior:

No Typecheck error.

It is interesting that if we remove explicit string type for key the code is not compilable as expected.

Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=4&pc=1#code/MYewdgzgLgBARjAvDA3jAhgLhgcgBYCmANkSDjAL4DcAsAFCiSwDWBAnttAE4CWYA5klyESZWg3DQM2AEoFQXACYAebn34AaGGoEA+IWgB0xuFoDarNgF1sAVzCKCAMz4FFlcUA

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions