November 2018
Beginner
502 pages
10h 22m
English
The final tuple enhancement in TypeScript 3 is the ability to have optional elements. Optional elements are specified using a ? at the end of the element type.
Let's look at another example using our scores theme:
type Scores = [number, number?, number?];
const samScores: Scores = [55];const bobScores: Scores = [95, 75];const jayneScores: Scores = [65, 50, 70];
As expected, this compiles just fine.
const sarahScores: Scores = [95, 50, 75, 75];
We get a compilation error, as we would expect:
Read now
Unlock full access