Reputation: 99960
I have this exported function:
export function foo(){
setTimeout(function(){
foo.x = y; // add a property to foo fn
},3000);
}
how can I declare with TypeScript that foo may have a property called "x"?
my only guess would be to do something like this:
export const foo : FooType = function(){
setTimeout(function(){
foo.x = y; // add a property to foo fn
},3000);
}
where FooType is an interface like:
interface FooType {
foo?: YType
}
but I don't think that solution works.
Upvotes: 0
Views: 38
Reputation: 40544
Your interface should work. In fact you can add the function signature itself to the interface:
interface FooType {
(): void;
x?: string
}
export const foo: FooType = function () {
setTimeout(function () {
foo.x = "some value";
}, 3000);
}
Upvotes: 1