Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript weird type

Tags:

typescript

I've come across this type:

let a: [number | string];

I've googled and looked at the Typescript docs but I don't see this syntax mentioned. What is it, I see the base is a union of string or number but it's not a tuple nor is it an array. What does it correspond to? Can anyone explain in simple terms and how to initialise it and add values please.

like image 907
Jacobs Avatar asked Sep 27 '26 06:09

Jacobs


1 Answers

It is a tuple of size 1. Contains either a number or a string

like image 79
ᅙᄉᅙ Avatar answered Sep 28 '26 22:09

ᅙᄉᅙ