Sasgorilla
Sasgorilla

Reputation: 3130

Can I extend a Typescript tuple type?

Say I have a Typescript tuple:

type Sandwich = [name: string, toppings: object]

Now I want to extend it:

type HotDog = [name: string, toppings: object, length: number]

Can HotDog extend Sandwich without duplication?

Upvotes: 1

Views: 180

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187024

Just spread one into the other:

type Sandwich = [name: string, toppings: object]
type HotDog = [...sandwich: Sandwich, length: number]
//   ^ type is [name: string, toppings: object, length: number]

See Playground

Upvotes: 2

Related Questions