The following code snippet passes typescript checks
function foo(callback: (bool: boolean) => string) {
callback(true);
}
type Interface1 = {
func1: () => string;
};
const testFunction = (str: string = '') => str.toLowerCase();
const variable: Interface1 = { func1: testFunction };
// No typescript error, but will raise error on runtime
foo(variable.func1);
whereas the following statement throws a typescript error
foo(testFunction);
How could we catch this error at compile time?
New contributor
Prithiv Krishna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.