Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes inferred args type of expectSaga and testSaga #387

Merged
merged 1 commit into from
May 13, 2022
Merged

Fixes inferred args type of expectSaga and testSaga #387

merged 1 commit into from
May 13, 2022

Conversation

lourd
Copy link
Contributor

@lourd lourd commented May 13, 2022

This makes a small tweak to how the parameters for a saga given to expectSaga or testSaga are inferred.

This snippet does not work with the latest version, 4.0.4 and TypeScript 4.6

function* helperSaga<T>(foo: T, saga: (item: T) => any) {
  yield saga(channel);
}

function* handler(num: number) {
  yield num;
}

expectSaga(helperSaga, 42, handler);

The TypeScript compiler has an error on the last line:

function handler(num: number): Generator<number, void, unknown>
Argument of type '(num: number) => Generator<number, void, unknown>' is not assignable to parameter of type '(item: unknown) => any'.
  Types of parameters 'num' and 'item' are incompatible.
    Type 'unknown' is not assignable to type 'number'.ts(2345)

By making the type for the saga's params inferred as a generic type parameter and passing that through to SagaType as a type parameter, the compiler infers them correctly and the error is resolved.

@jp928
Copy link
Collaborator

jp928 commented May 13, 2022

@lourd Many thanks for your PR.

@jp928 jp928 merged commit d56195e into jfairbank:master May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants