HomeInterview QuestionsWhat is a union type?

What is a union type?

🟢 Easy Conceptual Fresher level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

A union type is a type that can be one of several types. In TypeScript, you can declare a variable that can hold either a string or a number using the | operator. Example: let id: string | number; id = 'abc'; id = 123; This allows flexibility while still providing type safety. Union types are useful for functions that accept multiple input types, for discriminated unions, and for modeling data that can take on several forms.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500