How do you restrict a prop to have values from a specific string literal union using TypeScript?
- By using TypeScript's StringLiteral type.
- By using TypeScript's Enum type.
- By defining a custom type with specific string values.
- You cannot restrict props to a specific string literal union in TypeScript.
To restrict a prop to have values from a specific string literal union using TypeScript, you can achieve this by defining a custom type with specific string values. This allows you to create a type that represents only the allowable string values for the prop. The other options mentioned are not standard practices for restricting props to specific string literal unions in TypeScript.
Loading...
Related Quiz
- What are error boundaries in React v16?
- What is Relay?
- Your React application's user base is global, with a significant number of users from regions with slow internet connections. Which strategy would you adopt to ensure the application loads quickly and reliably for all users?
- Prop drilling refers to the practice of passing ________ through multiple levels of components.
- How to combine multiple inline style objects?