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
113
아이템 19 추론 가능한 타입을 사용해 장황한 코드 방지하기
logProduct(furby);
// ~~~~~ ...
형식의
인수는
'Product'
형식의
매개변수에
할당될
수
없습니다
.
// 'id'
속성의
형식이
호환되지
않습니다
.
// 'number'
형식은
'string'
형식에
할당할
수
없습니다
.
그러나 타입 구문을 제대로 명시한다면, 실제로 실수가 발생한 부분에 오류를
표시해 줍니다.
const furby: Product
=
{
name: 'Furby',
id: 630509430963,
// ~~ 'number'
형식은
'string'
형식에
할당할
수
없습니다
.
price: 35,
};
logProduct(furby);
마찬가지로 함수의 반환에도 타입을 명시하여 오류를 방지할 수 있습니다. 타
입 추론이 가능할지라도 구현상의 오류가 함수를 호출한 곳까지 영향을 미치
지 않도록 하기 위해 타입 구문을 명시하는 게 좋습니다.
주식 시세를 조회하는 함수를 작성했다고 가정해 보겠습니다.
function getQuote(ticker: string) {
return fetch(`https://quotes.example.com/?q
=
${ticker}`)
.then(response
=
> response.json());
}
이미 조회한 ...
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