agiledigital / typed-redux-saga

An attempt to bring better TypeScript typing to redux-saga.
MIT License
315 stars 33 forks source link

Regression in latest release? (when upgrading from 1.4 to 1.5) #677

Open osmestad opened 1 year ago

osmestad commented 1 year ago

Hi,

I added a PR with two examples of cases that started failing for us when trying to apply the update: #675

The smallest case looks like this:

  function handleArgumentThatIsPartOfUnion(requestId: 27 | 28) {
    return 22;
  }
  yield* Effects.call(handleArgumentThatIsPartOfUnion, 27);

This code works in 1.4 but in 1.5 the argument to the function called (27) gets interpreted as number (instead of that specific number it seems?)

Has anyone else had this problem? ideas to fix it?

stengard commented 1 year ago

I think this is related:

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

interface DownloadFileProgress {
  onDownloadProgress: (data: { total: number; loaded: number }) => void;
}

export const downloadAudioFile = function* (
  fileId: string,
  { onDownloadProgress }: Partial<DownloadFileProgress>
) {
  // download file
};

function* test() {
  yield* call(downloadAudioFile, "some-id", {
    // total and loaded is any
    onDownloadProgress: ({ total, loaded }) => {

    }
  });
}

in 1.5 the parameters of onDownloadProgress is inferred as any

in 1.4 it works as expected, loaded and total is number.

https://codesandbox.io/s/billowing-water-vlnhey?file=/src/index.ts

kevich commented 1 year ago

Hello everyone! I still think there is some regression with string literals:

import { call } from 'typed-redux-saga';
import { SagaIterator } from 'redux-saga';

type StringLiteral = 'GET' | 'POST' | 'PUT' | 'DELETE';

type ObjectWithLiteral = {
    method: StringLiteral,
};

function simpleOne(object: ObjectWithLiteral): StringLiteral {
    return object.method;
}

function* generator(object: ObjectWithLiteral): SagaIterator<StringLiteral> {
    return object.method;
}

function* test(): SagaIterator<void> {
    // shows error
    const a = yield* call(simpleOne, {method: 'GET'});
    // shows error
    const b = yield* call(generator, {method: 'GET'});
}

// do not show error, which is correct behaviour according to latest typescript
simpleOne({method: 'GET'});
yvoychuk commented 1 year ago

I have the same problem (version 1.5) - I'm using untyped call as a workaround. It would be nice to find fix for this issue.

osmestad commented 7 months ago

We have had to stay on 1.4 to avoid these issues :-(