Kod Yazma · TypeScript
Tagged Union
Exhaustive handling of a discriminated type.
Zorluk: Orta · 15 Satır · Lisans: public-domain
type Shape =
| { kind: 'circle'; radius: number }
| { kind: 'square'; side: number }
| { kind: 'rectangle'; width: number; height: number };
function area(shape: Shape): number {
switch (shape.kind) {
case 'circle':
return Math.PI * shape.radius ** 2;
Süre0:00
Hız (WPM)0.0
Doğruluk100.0%
Hata0
Canlı Klavye
Sıradaki Tuş: T | Son Basılan: -
İlerleme: 0.0%
"
1
2
3
4
5
6
7
8
9
0
*
-
Q
W
E
R
T
Y
U
I
O
P
Ğ
Ü
A
S
D
F
G
H
J
K
L
Ş
İ
Z
X
C
V
B
N
M
Ö
Ç
.
Boşluk
Süreli Test Leaderboard
Henüz sonuç yok. İlk sırayı sen al.