🔎 Search Terms
class expression private fields assignability
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground Link
💻 Code
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
🔎 Search Terms
class expression private fields assignability
🕗 Version & Regression Information
⏯ Playground Link
Playground Link
💻 Code
🙁 Actual behavior
c2is assignable toc1even though they contain private fields that are different (even if they come from the same source code)🙂 Expected behavior
Instances of
cls2should not be assignable tocls1since they have different versions of the private field.Additional information about the issue
Found as I was exploring the consequences of #56145