Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Reactotron.log + typescript - cannot invoke an object which is possibly 'undefined' #239

Closed

Description

@doronnac

reactotron-react-native v4.0.3

import Reactotron from 'reactotron-react-native'
Reactotron.log() // <-- Cannot invoke an object which is possibly 'undefined'

Saw a similar issue which was supposedly resolved. Maybe I'm missing something?

Activity

  1. DavidNeiOs commented on Apr 19, 2020

    @DavidNeiOs

    I found a temporary solution in this thread #168 (comment)
    @doronnac

  2. leotm commented on Jul 13, 2020

    @leotm

    Since in our ReactotronCore interface log?: (...args: any[]) => void is an optional function, we just need to assert it's not null when calling it:

    Reactotron.log!('hey there')

    Same goes for any other optional functions you're calling like warn, error, etc.

    Use newer optional chaining (TS 3.7+) if preferred.

    Bonus: Here's a way to add type safety with linting

  3. patrick-narciso commented on Jul 16, 2020

    @patrick-narciso

    The @leotm solution is correct, it even works for other cases such as when using Reactotron.createEnhancer!()

  4. AndreCosta101 commented on Feb 25, 2021

    @AndreCosta101

    The @leotm solution is correct, it even works for other cases such as when using Reactotron.createEnhancer!()

    Hey Patrick... you mean in the store configuration? How did you do it ? thanks

  5. dbishopdev commented on May 24, 2021

    @dbishopdev

    Hey Patrick... you mean in the store configuration? How did you do it ? thanks

    @AndreCosta101 Something like this:

    import { createStore } from "redux";
    import Reactotron from "../ReactotronConfig";
    import rootReducer from "./reducers";
    
    export default createStore(rootReducer, Reactotron.createEnhancer!());
    
  6. GermaVinsmoke commented on Dec 16, 2021

    @GermaVinsmoke

    But this solution gives this warning - "Forbidden non-null assertion."
    Is it okay to have this warning?

  7. leotm commented on Feb 10, 2022

    @leotm

    @GermaVinsmoke

    Use newer optional chaining if preferred.

    Reactotron.log?.('hey there')

    Since TypeScript 3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions