- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
π Search Terms
class expression private fields assignability
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
function makeClass(v: number) {
    return class C{
        #id = v;
        static getId(o: C) {
            return o.#id;
        }
    }
}
const cls1 = makeClass(1)
const cls2 = makeClass(2)
let c1 = new cls2(); // TS thinks this is ok
cls1.getId(c1) // runtime error different versions of #idπ Actual behavior
c2 is assignable to c1 even though they contain private fields that are different (even if they come from the same source code)
π Expected behavior
Instances of cls2 should not be assignable to cls1 since they have different versions of the private field.
Additional information about the issue
Found as I was exploring the consequences of #56145
rotu
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed