Objective: Developing a type guard for a unique custom type.
Introducing my custom data type:
type AppProviders = 'box' | 'dropbox' | 'google';
This represents my initial endeavor to create a type guard, though it appears repetitive as I specify allowed values twice:
type AppProviders = 'box' | 'dropbox' | 'google';
const appProviders: AppProviders[] = [ 'box', 'dropbox', 'google' ];
function isAppProviders(provider): provider is AppProviders {
return appProviders.includes(provider)
}
Is there an improved method for implementing a type guard with custom literal types?
Appreciate your insights