Skip to content

Readonly-ness is lost in function call #33748

Description

@thecotne

TypeScript Version: 3.6.3

Search Terms:

Code

type EditablePerson = {
    name: string
}
type ReadonlyPerson = {
    readonly name: string
}

const editablecotne: EditablePerson = {
    name: 'cotne'
}
const readonlycotne: ReadonlyPerson = {
    name: 'cotne'
}

function updateName (person: EditablePerson, newName: string) {
    person.name = newName
}

//ok
editablecotne.name = 'not so cotne'
updateName(editablecotne, 'not so cotne')

//err
readonlycotne.name = 'not so cotne'// ok
updateName(readonlycotne, 'not so cotne')//fuck!

Expected behavior:
you can't modify readonly property of object

Actual behavior:
you can pass object to function and edit it there

Playground Link: try

Related Issues:

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