TypeScript · Senior · Pytanie 61 z 75
Czego wymaga funkcja asercji, by jej wywołanie zawężało typ?
const assertUser: (x: unknown) => asserts x is User = (x) => { /* ... */ };- ✓Poprawna odpowiedź: Wywoływana funkcja musi mieć jawną adnotację typu (strzałki bez niej nie da się użyć jako asercji)
- 2Musi być metodą klasy
- 3Musi zwracać
true
Wyjaśnienie
Inaczej TypeScript zgłosi „Assertions require every name in the call target to be declared with an explicit type annotation”.