TypeScript: Why you have to add types even if you handle the undefined case

preview_player
Показать описание

I later came to understand why it was important to add types for it. Here's an explanation for why.
Рекомендации по теме
Комментарии
Автор

You can do foo.bar! which explicitly tells ts compiler that bar is not undefined.

wire_surfer
Автор

Why so secretive about reason behind learning TypeScript 🤔

gabriel_ts
Автор

There is no problem in JS. You are solving the problem that doesn't exist in JS

➞ node
>
> const foo = {}
> const bar = typeof foo.bar === 'string' ? foo.bar : 'history'
> console.log(bar.slice(0, 3))
his

AlexNudelman
Автор

The idea of types is good, but typescript is is too much strict
.

natqe
join shbcf.ru