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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)