I'd like to use Java-style functional interfaces in TypeScript. Meaning, I'd like to have an interface with exactly one method, and I'd like to be able to supply just the method wherever that interface is expected. Here's what I've tried:
interface Observer<T> {
observe(t: T);
}
function addObserver<T>(observer: Observer<T>) {
// calls observer.observe at some point
}
// works
addObserver({
observe: t => console.log(t)
});
// Property 'observe' is missing
addObserver(t => console.log(t));
How do I accomplish this in TypeScript?