There seem to be two ways to declare a named function in an interface in Typescript:
export interface Zoo {
foo(): string
readonly bar: () => string,
}
Two questions:
- What is the difference between foo and bar functions?
- Why is there only readonly modifier for the panel?
UPDATE:
Here is a longer example:
export interface Zoo {
foo(): string
readonly bar: () => string,
}
export const x: Zoo = {
foo: () => "a",
bar: () => "a",
};
x.foo = () => "b"; // No error
x.bar = () => "b"; // Error: Cannot assign to "bar"
It seems to me that both ways of declaring are equivalent, except that the second way can be done read-only.
I also found this older answer saying that they are equivalent, with the exception of the possibility of overload.
source
share