What TypeScript pattern can I use to enforce that a function gets a property?
- by Matt York
In JavaScript I can do this:
function f() {}
f.prop = "property";
I want this in TypeScript, but with type checking.
What TypeScript pattern can I use to enforce that a function gets a property?
Could I use an interface?
interface functionWithProperty {
(): any;
prop: string;
}
This seems to be a valid interface in TypeScript, but…