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
{{ message }}
Repository navigation
this type should return instance type when overridden #2904
AssemblyScript seems to recognize this syntax and compiles fine:
classX{doSomething(): this {returnthis;}}
However, in AssemblyScript, it always is treated as the class where this is used - which is not necessarily the type of the instance when the object is extended.
classYextendsX{doSomethingElse(): string{return"You made it!";}}
ERROR TS2339: Property 'doSomethingElse' does not exist on type 'assembly/index/X'.
:
12 │ console.log(new Y().doSomething().doSomethingElse());
│ ~~~~~~~~~~~~~~~
└─ in assembly/index.ts(12,35)
Essentially, y.doSomething() is returning a type X where it should return a type Y.
TypeScript tooling believes the value should be Y, but AssemblyScript thinks it's X.
Casting the value using <Y> or as Y works, but the point is that one may have full awareness of the original type when making the call.
Activity
mattjohnsonpint commentedon Feb 3, 2025
I think perhaps this may have been overlooked when implementing #1208 for #693.
mattjohnsonpint commentedon Feb 5, 2025
I think this gives a clue to the issue:
assemblyscript/src/resolver.ts
Lines 2859 to 2861 in 9a7a6e0
The function prototype is
X.doSomething, so theclassInstanceisX(notY).I think I will try to fix this. PR forthcoming...