Skip to content

Spread operator with computed property is not being checkedΒ #63585

Description

@val-o

πŸ”Ž Search Terms

spread, computed property, unsoundness

πŸ•— Version & Regression Information

For any TS version

⏯ Playground Link

LINK

πŸ’» Code

type MyKey = 'key-1' | 'key-2'

interface Obj {
    a: number
}

type MyRecord = Record<MyKey, Obj>

declare const someRecord: MyRecord
declare const key: MyKey

const overriden: MyRecord = {
    ...someRecord,
    [key]: 'anything is oke here, why?'
}

πŸ™ Actual behavior

No type check errors

πŸ™‚ Expected behavior

On line 14, we assign string ''anything is oke here, why?'' as a value of a MyRecord type, whose value are typed as interface with one number property. This should lead to error since in runtime the record no longer will have values of type Obj

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions