Type Widening and Type Narrowing in TypeScript

Type Widening and Type Narrowing in TypeScript

TypeScript TV with Benny

54 года назад

632 Просмотров

TypeScript internally makes use of type widening and type narrowing. Type narrowing reduces the possibilities of values which a variable can take. The opposite case is called type widening. This video shows you these special cases and how to work with them.

*My FREE programming apps:*
- https://apps.apple.com/app/id659282498
- https://play.google.com/store/apps/details?id=com.welovecoding.app

*My FREE TypeScript Course:*
- https://typescript.tv/

Timeline:
00:00 Wide Types & Narrow Types
02:10 Type Widening & Type Narrowing
02:46 Type Widening in Variables
05:45 Type Widening in Arrays
07:37 Type Widening in Functions
09:55 Type Narrowing for union types
13:34 Type Widening in Literals

TypeScript errors being shown: TS2322, TS2345 & TS2367.

Resources:
https://github.com/microsoft/TypeScript-New-Handbook/blob/master/reference/Widening-and-Narrowing.md
https://github.com/Microsoft/TypeScript/pull/10676

Follow TypeScript TV:
🌐 https://typescript.tv
🐦 https://twitter.com/typescripttv
📺 https://youtube.com/typescripttv​

Hashtags:
#TypeScript #JavaScript #CodeNewbie #Programming

Тэги:

#typescript
Ссылки и html тэги не поддерживаются


Комментарии: