TypeScript

Choosing a discriminant (kind, type, status)

Në shqip: Zgjedhja e fushës diskriminuese

ShpjegimiSQ

Te discriminated unions, zgjidh një emër të qëndrueshëm për fushën dalluese — kind, type ose status — dhe përdore në gjithë projektin. Vlerat literal ("ngarkim", "sukses", "gabim") e bëjnë kodin vetë-shpjegues.

EnglishEN

In discriminated unions, choose a consistent name for the distinguishing field — kind, type or status — and use it project-wide. Literal values ("loading", "success", "error") make the code self-explanatory.

Si ta mendosh

Si ngjyrat e biletave: çdo ngjyrë tregon menjëherë llojin.

Lexoje në anglisht

Like ticket colours: each colour tells you the type at a glance.

Shembull koditypescript

type Gjendja =
  | { status: "ngarkim" }
  | { status: "sukses"; te_dhenat: string[] }
  | { status: "gabim"; mesazhi: string };

Terma të lidhur