Although your code is correct, the types you've used are incorrect. Your function interface is supposed to be a function that returns another function, but the testCode
function does not actually return anything.
This code works perfectly fine with TypeScript version 3.1 or later
interface MyCode {
(): Function;
title: string;
}
const testCode: MyCode = () => () => {};
testCode.title = 'my first function';
If you prefer an alternative method, you can achieve the same result using namespaces
function testCode() {
return () => {};
}
namespace testCode {
export const title = '';
}
Another option is to use Object.assign()
const testCode: MyCode = Object.assign(() => () => {}, {
title: 'my first function'
});