typed-redux-saga icon indicating copy to clipboard operation
typed-redux-saga copied to clipboard

Macro doesn't seem to do anything

Open OnkelTem opened this issue 3 years ago • 2 comments

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:

@...
├─┬ [email protected]
│ └─┬ [email protected]
│   └── [email protected] deduped
└─┬ [email protected]
  └── [email protected]

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

OnkelTem avatar Mar 02 '21 17:03 OnkelTem

I also having this issue.

xitox97 avatar Apr 26 '21 07:04 xitox97

I am also having this issue.

Bohooslav avatar Jul 11 '23 14:07 Bohooslav