1
interface MyState {
  balances: { [address: string]: BN };
}

const [ state, setState ] = useState</* what should I do? */>({});

I want to pass type of MyState.balances to useState's generic type like useState<typeof MyState.balances>({}), but it didn't work.

How can I do that?

1
  • @RobbyCornelissen didn't work. ts(2693) error occurred. 'MyState' Only refers to a type, but is being used as a value here Commented Jul 8, 2022 at 3:49

1 Answer 1

1

You can use an indexed access type:

interface MyState {
  balances: { [address: string]: BN };
}

const [ state, setState ] = useState<MyState['balances']>({});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.