Skip to content

[Bug] Result of object rest isn't assignable to symbol index signatureΒ #49235

@sounisi5011

Description

@sounisi5011

Bug Report

πŸ”Ž Search Terms

  • PropertyDescriptorMap
  • PropertyDescriptor
  • Spread

πŸ•— Version & Regression Information

  • This has changed since version 4.6

⏯ Playground Link

Playground link with relevant code:

πŸ’» Code

declare const properties1: { [x: string]: PropertyDescriptor };

// This will pass. This is because the type '{ [x: string]: PropertyDescriptor }' can be assigned to the type 'PropertyDescriptorMap'.
Object.defineProperties({}, properties1);

// But when it passes the spread syntax, it fails even though the types are the same.
const { ...properties2 } = properties1;
Object.defineProperties({}, properties2);

πŸ™ Actual behavior

I get the following error:

Argument of type '{ [x: string]: PropertyDescriptor; }' is not assignable to parameter of type 'PropertyDescriptorMap & ThisType<any>'.
  Type '{ [x: string]: PropertyDescriptor; }' is not assignable to type 'PropertyDescriptorMap'.
    Index signature for type 'symbol' is missing in type '{ [x: string]: PropertyDescriptor; }'.

But, type { [x: string]: PropertyDescriptor; } is assignable to type PropertyDescriptorMap. Objects copied with spread syntax cannot be assigned even though they have the same type.

πŸ™‚ Expected behavior

This type error does not occur. For the same type, it should be consistently assignable / non-assignable anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions