1

I have a type like this,

interface StyleProps {
  display?: 'hide' | 'active'
}

and the type is being used by component below

<Section display={`${this.state.section !== 'chatbot' ? 'hide' : 'active'}`}>

display can only be hide or active but I'm still getting this error

 TS2322: Type 'string' is not assignable to type '"hide" | "active" | undefined'.

Is there any way to see what's in display or anything im doing it wrong?

0

1 Answer 1

2

You can get rid of this error if you remove the template literal and just pass in either 'hide' or 'active' directly.

<Section display={this.state.section !== 'chatbot' ? 'hide' : 'active'}>
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.