Double assertion (as unknown as T)
Në shqip: Pohimi i dyfishtë
ShpjegimiSQ
Kur TypeScript-i s'të lejon një as sepse tipet s'kanë lidhje fare, disa shkruajnë x as unknown as T. Funksionon, por e fik plotësisht kontrollin — zakonisht është shenjë që diçka në tipe është gabim.
EnglishEN
When TypeScript won't allow an as because the types are completely unrelated, some people write x as unknown as T. It works, but it switches checking off completely — usually a sign something in your types is wrong.
Si ta mendosh
Si ta ngjitësh një etiketë të re mbi një kuti pa e hapur fare.
Lexoje në anglisht
Like sticking a new label on a box without ever opening it.
Shembull koditypescript
const n = "5" as unknown as number; // kompajlohet… por është gënjeshtër