Reputation: 73
Can I specify an array as a type in Typescript and then any subset of this array is allowed to be passed?
E.g.
type Actions = ['view', 'share', 'delete']
const concatActions = (actions: Actions) => actions.join();
concatActions(['view', 'delete']) // Works
concatActions(['share']) // Works
concatActions(['view', 'some_other_action']) // Throws type error
Upvotes: 0
Views: 35
Reputation: 945
This should work
type Action = 'view' | 'share' | 'delete'
type Actions = Action[]
Upvotes: 2