agiledigital / typed-redux-saga

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

Macro doesn't seem to do anything #459

Open OnkelTem opened 3 years ago

OnkelTem commented 3 years ago
import { select } from 'typed-redux-saga/macro';

const getToken = (state: RootState) => state.user.account?.token; // type: (...) => string | undefined

function* fetchAlertsSaga() {
  const token = yield select(getToken); 
  // TypeScript error here 
  // TS7057: 'yield' expression implicitly results in an 'any' type because 
  //   its containing generator lacks a return-type annotation.
  // ...
}

babel-plugin-macros is installed via react-scripts dependencies:

@...
├─┬ react-scripts@4.0.3
│ └─┬ babel-preset-react-app@10.0.0
│   └── babel-plugin-macros@2.8.0 deduped
└─┬ typed-redux-saga@1.3.1
  └── babel-plugin-macros@2.8.0

What I do wrong? Should I configure macro somehow?

If I switch import of typed-redux-saga/macro to the typed-redux-saga and add '*' to the yields, the correct type is inferred:

  const token = yield* select(getToken);  // string | undefined
xitox97 commented 3 years ago

I also having this issue.

Bohooslav commented 1 year ago

I am also having this issue.