reactotron icon indicating copy to clipboard operation
reactotron copied to clipboard

Missing type `createEnhancer` when using with typescript

Open raulmax319 opened this issue 3 years ago • 2 comments

When using redux with reactotron i get the following problem message when using with typescript. Property 'createEnhancer' does not exist on type 'Reactotron<ReactotronReactNative> & ReactotronReactNative'.ts(2339)

Here what my code looks like:

createStore.ts

import { createStore, applyMiddleware, Store, compose } from 'redux';
import thunk from 'redux-thunk';

import { ReactotronInstance as Reactotron } from '~/services/reactotron';
import rootReducer from './rootReducer';

const enhancer = __DEV__
  ? compose(Reactotron.createEnhancer(), applyMiddleware(thunk))
  : applyMiddleware(thunk);

export const store: Store = createStore(rootReducer, enhancer);

reactotron.ts

import Tron from 'reactotron-react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {
  ReactotronConfig,
  DEFAULT_REACTOTRON_CONFIG,
} from './reactotronConfig';
import { RootNavigation } from '~/navigator';
import { clear } from '~/utils/storage';

declare global {
  interface Console {
    tron: typeof Tron;
  }
}

let ReactotronInstance: typeof Tron;
const config: ReactotronConfig = DEFAULT_REACTOTRON_CONFIG;

if (__DEV__) {
  const Reactotron = require('reactotron-react-native').default;

  const { reactotronRedux } = require('reactotron-redux');

  ReactotronInstance = Reactotron.setAsyncStorageHandler(AsyncStorage)
    .configure({
      name: config.name || require('../../../package.json').name,
    })
    .useReactNative({
      asyncStorage: config.useAsyncStorage ? undefined : false,
    })
    .use(reactotronRedux())
    .connect();
}

ReactotronInstance.clear();

console.tron = ReactotronInstance;

export { ReactotronInstance };

raulmax319 avatar Apr 25 '21 14:04 raulmax319

any solution here ?

yaser-elbatal avatar Mar 10 '22 14:03 yaser-elbatal

image I catch this error? Any solution please. thanh you

NgocLe1001 avatar Mar 13 '22 06:03 NgocLe1001

Similar but not identical resolved issue of using with Redux Tookit https://stackoverflow.com/questions/73358881/how-we-configure-reactotron-with-reduxjs-tookkit

With Redux Toolkit + typescript, in store.ts, I successfully used the exclamation point to ignore the missing type:

export const store = configureStore({
    reducer: {
        c: cReducer,
        auth: authReducer,
    },
    enhancers: [
        Reactotron.createEnhancer!(),
    ],
})

thadk avatar Nov 03 '22 22:11 thadk

Screenshot 2023-08-07 at 11 29 13

@thadk Hi, thanks for your answer, I'm facing another issue with jest test. Is anyone facing the same issue? Thank you guys!

vdr-mm-quan avatar Aug 07 '23 04:08 vdr-mm-quan

Screenshot 2023-08-07 at 11 29 13 @thadk Hi, thanks for your answer, I'm facing another issue with jest test. Is anyone facing the same issue? Thank you guys!

woker me


const enhancers = Reactotron?.createEnhancer
  ? composeEnhancers(applyMiddleware(...middlewares), Reactotron.createEnhancer())
  : composeEnhancers(applyMiddleware(...middlewares));

const store = createStore(persistedReducer, enhancers);

MarcosSarges avatar Oct 09 '23 14:10 MarcosSarges

try [(Reactotron as any).createEnhancer()] it work for me

phuocantd avatar Jan 12 '24 08:01 phuocantd