Skip to content

core: remove redundant Record constructors that defeat Immutable.js defaults #213

@bpowers

Description

@bpowers

Every Record subclass in src/core/datamodel.ts defines an explicit constructor(props: typeof defaults) with the comment "this isn't useless, as it ensures we specify the full object." However, Immutable.js's Record() factory already produces a constructor typed as Partial<TProps> -- omitted fields automatically receive the default value from the defaults object. The explicit constructors override this to require all fields, which defeats the purpose of having defaults in the first place.

The practical consequence is that adding a new optional field with a sensible default (e.g. polarity: undefined) to any Record type breaks every existing callsite, even though callers have no reason to explicitly pass undefined. There are ~27 Record subclasses with this pattern. The fix is straightforward: remove the explicit constructors and let the Record() factory's built-in Partial<TProps> constructor handle it. Callers that already pass all fields will continue to work, and callers that omit optional fields will get the defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions