Implementing Interface functions throw duplicate identifier
Hi there, I believe I found a bug. I've read through the documentation and searched the internet to see if I'm misunderstanding something. However nothing seems to jump out to me as incorrect.
Steps to reproduce
- Go to AS playground or create a new AS project
- Create a new ts file and paste the following code
interface IFoo {
doSomething: () => void;
}
export class Bar implements IFoo {
doSomething(): void {
}
}
Expected result Build should pass without errors. The TS compiler recognizes the code as valid
Actual result ERROR TS2300: Duplicate identifier 'doSomething'.
This is due to declaring doSomething as a property and then in the class you implement it as a method. Changing the interface to declare a method fixes it.
You can also implement doSomething like get doSomething(): () => void { return () => {} }, but since AS currently lacks closures you wouldn't have access to this.
Yes, that's a bug. Quick workaround is using doSomething(): void; instead doSomething: () => void;.
@dcodeIO will be great generalize function expressions and function declarations
Not easy I fear, because one is a mutable field one can re-assign that is called indirectly while the other is an immutable method called directly. Perhaps with a readonly modifier, not sure.
Wait is it possible reassign expression based method in AS?
Ah that makes sense! I was getting thrown off by the TS compiler not flagging anything, and yet the AS was flagging it. Thanks guys. Really excited to see where AS goes :)