Lambda
Lambda

Reputation: 3

TypeScript object Array type definition

What is the difference between this two type definitions?

type objectArray = [object]

type objectArray = object[]

Upvotes: 0

Views: 817

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371128

[object] is a tuple. It's the type of an array with a single value in it, and the value must be an object.

object[] is the same as Array<object>. It's the type of an array with any number of values, where any such values must be object.

All tuples are arrays, but a tuple is a more restrictive type of array, with a specified number of elements.

Upvotes: 1

Related Questions