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

Yielded value from 'call' have type 'unknown' #647

Open
ekabolotina opened this issue Nov 10, 2021 · 1 comment
Open

Yielded value from 'call' have type 'unknown' #647

ekabolotina opened this issue Nov 10, 2021 · 1 comment

Comments

@ekabolotina
Copy link

Hi everyone! I have just bumped into the situation:

import { call } from "typed-redux-saga";

type Product = {
    id: number;
    name: string;
}

type ProductExtended = Product & {
    weight: number;
}

export function normalizeProduct<T extends Partial<Product>>(product: T): T {
    const { name = '' } = product;

    return {
        ...product,
        name: name.trim(),
    };
}

function* saga(productExtended: ProductExtended) {
    const productExtendedNormalized = yield* call(normalizeProduct, productExtended);
    // productExtendedNormalized is now of type 'unknown', but expected type is 'ProductExtended'
}
@nam-hle
Copy link

nam-hle commented Dec 2, 2021

Maybe the issue is from SagaReturnType. Rewrite it as below could fix:

export type SagaReturnType<
  S extends (...args: any[]) => any,
  T = ReturnType<S>,
> = T extends SagaIterator<infer RT>
  ? RT
  : T extends Promise<infer RT>
  ? RT
  : T extends infer RT
  ? RT
  : never;

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

No branches or pull requests

2 participants