Skip to content

Spreading identical values with properties and indexers creates errors #8276

@chrbala

Description

@chrbala

Similar to #8178, but with an additional property. Spreading identical values with properties and indexers creates errors.

export type Trie<T> = {
  [string]: Trie<T>,
  _?: T,
};

const x: Trie<number> = { };
const y: Trie<number> = { };

const z: Trie<number> = { ...x, ...y };

Flow version: 0.117.0

Expected behavior

Two values with identical types should always be spreadable

Actual behavior

Error is thrown:

    11: const z: Trie<number> = { ...x, ...y };
                                           ^ Cannot determine a type for object literal [1]. `Trie` [2] cannot be spread because the indexer string [3] may overwrite properties with explicit keys in a way that Flow cannot track. Can you spread `Trie` [2] first or remove the indexer?
        References:
        11: const z: Trie<number> = { ...x, ...y };
                                    ^ [1]
        9: const y: Trie<number> = { };
                    ^ [2]
        4:   [string]: Trie<T>,
              ^ [3]
  • Link to Try-Flow or Github repo: tryflow

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions