Skip to Content
이펙티브 타입스크립트
book

이펙티브 타입스크립트

by Dan Vanderkam, Won Ho Jang
November 2021
Intermediate to advanced
364 pages
9h 52m
Korean
Insight
Content preview from 이펙티브 타입스크립트
TypeScript
169
아이템 31 타입 주변에 null 값 배치하기
󻨓󻱃󼘫 󼖏󻱔󽴔󻷋󻆏󻪟󺃡󽴔󻃿󼌧󼨧󺋿
strictNullChecks
설정을 처음 켜면,
null
이나
undefined
값 관련된 오류들이
갑자기 나타나기 때문에, 오류를 걸러 내는
if
구문을 코드 전체에 추가해야 한
다고 생각할 수 있습니다. 왜냐하면 어떤 변수가
null
이 될 수 있는지 없는지를
타입만으로는 명확하게 표현하기 어렵기 때문입니다. 예를 들어
B
변수가
A
변
수의 값으로부터 비롯되는 값이라면,
A
가
null
이 될 수 없을 때
B
역시
null
이
될 수 없고, 그 반대로
A
가
null
이 될 수 있다면
B
역시
null
이 될 수 있습니다.
이러한 관계들은 겉으로 드러나지 않기 때문에 사람과 타입 체커 모두에게 혼
란스럽습니다.
값이 전부
null
이거나 전부
null
이 아닌 경우로 분명히 구분된다면, 값이 섞
여 있을 때보다 다루기 쉽습니다. 타입에
null
을 추가하는 방식으로 이러한 경
우를 모델링할 수 있습니다.
숫자들의 최솟값과 최댓값을 계산하는
extent
함수를 가정해 보겠습니다.
function extent(nums: number[]) {
let min, max;
for (const num of nums) {
if (!min) {
min
=
num;
max ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

러닝 타입스크립트

러닝 타입스크립트

조시 골드버그
고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트
타입스크립트 프로그래밍

타입스크립트 프로그래밍

Boris Czerny, U Jung Eun

Publisher Resources

ISBN: 9788966263134