Skip to content

Attribute for forcing copies of mutable types #34827

@kwasimensah

Description

@kwasimensah

I'm proposing an attribute that helps with tracking shallow copies vs deep copies/ownership semantics. I just spent a while tracking down a bug caused by this.

C++ surfaces errors like this because you're likely to pass in references as parameters but have to use values as member variables, to you're more likely to cause a copy than dangling reference

class Foo {
private /*magic_attribute */_bars : readonly string[]
constructor(bars : readonly string[]){
this._bars = bars // This line now complains because I didn't call bars.slice(0)
}
}

magic_attribute named something like owning_copy? copy_mutables?
I'm working with TypesScript 3.6.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions