What is the TypeScript equivalent of “PropTypes.oneOf” (restrict a variable to subset of values)

You can combine static strings (or any regular type) by defining a union type:

type SomeType="Home" | 'About';

Or within an interface:

interface SomeType {
  prop : 'Home' | 'About';
}

And of course you can combine other types as well:

type SomeType = string | boolean;

Leave a Comment