Skip to content

Record spread from smaller to bigger record type set doesn't work #6505

@ryyppy

Description

@ryyppy

I observed some weird behavior while working on my app, so I tried to reduce the problem to a minimal example.

type a = { title: string, ingredients: array<string>, } type b = { ...a, parsedIngredients: array<string>, } // This works let a: a = { title: "Pizza", ingredients: ["1 EL Oil", "1 EL flour"], } // EXPECTED: This should compile let b: b = { // ERROR: This has type `a`, but it's expected to have type `b` ...a, parsedIngredients: ["Oil", "Flour"], } 

I don't know if I misunderstood the record type spread feature, but IMO from an intuition perspective I'd expect value b to initialize just fine, since we are essentially spreading in all the values that a has, plus the parsedIngredients value that's required from b.

Does this work as expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions