Interface methods can not be implemented using object properties when the declared method has any parameters or a return type other than void i.e. is different to the default func type Func/Func<void>.
interface X {
fun: Func<num, num>; // <- property function
mul(a: num, b: num): num; // <- method declarator
}
var x: X = {
fun: (a: num): num -> a + 1,
mul: (a: num, b: num): num -> a * b, // <-- fails
};
print(x.fun(1)); // -> 2
print(x.mul(2, 2)); // <- fails
If you now change the method to be empty:
interface X {
mul(): void; // <- method declarator
}
var x: X = {
mul: (): void -> print("x"), // <-- works now
};
x.mul(); // <- works
Expected Behavior
Interfaces should allow the definition of a method with any given param and any return type.
Steps To Reproduce
Declare an interface with a method that has any parameter or any return type other than void.
Define the declared method using a standard property assignment expression inside an object.
Is there an existing issue for this?
I am following the documentation's guide
This issue exists in the latest version
Current Behavior
Interface methods can not be implemented using object properties when the declared method has any parameters or a return type other than
void
i.e. is different to the default func typeFunc
/Func<void>
.If you now change the method to be empty:
Expected Behavior
Steps To Reproduce
void
.Environment