I have some code that look like this:

const saga =  function* (action) {
        yield put({
            type: actions.SUCCESS,
            payload: action.payload
        });
    };


const sagaWatcher =  createDefaultSagaWatcher(actions, saga); 

That I am converting to TypeScript.

I need to create an interface for the generator function, so I can add type checking on the createDefaultSagaWatcher function. How do I do this?

I've tried doing something like this:

interface ReduxSaga {
    (action: ReduxAction)* : any; 
}

but that syntax is incorrect.

1 Answers

0
Titian Cernicova-Dragomir On

Much like the async modifier, the * is an implementation detail. The important part for the caller of the function is that the function returns something that can be iterated, how that iteration is implemented should not matter to the caller. Since you want the iteration to return anything you can use IterableIterator<any>

interface ReduxSaga {
    (action: ReduxAction): IterableIterator<any>; 
}