You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionmakeClass(v: number){returnclassC{
#id =v;staticgetId(o: C){returno.#id;}}}constcls1=makeClass(1)constcls2=makeClass(2)letc1=newcls2();// TS thinks this is okcls1.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
The text was updated successfully, but these errors were encountered:
I'm thinking this is probably a design limitation (i.e. nominally-typed properties are distinguished by source location or something), but yeah, ouch, that's unfortunate.
π Search Terms
class expression private fields assignability
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
c2
is assignable toc1
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 tocls1
since they have different versions of the private field.Additional information about the issue
Found as I was exploring the consequences of #56145
The text was updated successfully, but these errors were encountered: