GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledge of TypeScript.
Hands-on real world projects that will help you exercise your knowledge of TypeScript. - GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledg...
github.com
샐러드 재료들이 맛있어 보여요, 감사합니다!
다음은 내가 가장 좋아하는 요리법 목록입니다.
이것들은 TypeScript 컴파일러를 있는 그대로 잘 통과하는 것 같습니다.
그러나 문제가 있습니다. 향후 레시피가 동일한 난이도 및 그룹 타입을 유지하는지 확인하고 싶습니다.
리터럴 타입의 유니온을 사용해주시겠습니까? 둘 다 세 가지 가능한 값만 가져야 합니다.
이번에는 런타임 코드가 대부분 잘 작동합니다.
그러나 그룹 값 중 하나에 오타가 있습니다. 문제를 해결해야 합니다.
그렇지 않으면 타입 어노테이션을 수정해야 할 것입니다.
#파일
index.ts: 여기에서 타입 어노테이션 수정
solution.ts: 솔루션 코드
// Please clarify any overly wide (permissive) type annotations here! ✨
let difficulty: 1 | 2 | 3;
let group: "appetizer" | "entree" | "dessert";
let title: string;
// Start with something quick and painless to prepare...
difficulty = 1;
group = "appetizer";
title = "Raspberry Vinaigrette Salad";
console.log(`[${group}] ${title}: ${difficulty}/3 difficulty`);
// Next up, a nice hearty dish to center the meal...
difficulty = 2;
group = "entree";
title = "Cauliflower Steaks";
console.log(`[${group}] ${title}: ${difficulty}/3 difficulty`);
// Make a real impact with fancy delectable desserts...
difficulty = 3;
group = "dessert";
title = "Coconut Chocolate Ganache";
console.log(`[${group}] ${title}: ${difficulty}/3 difficulty`);
// Send everyone off with a nice closer.
difficulty = 1;
group = "dessert";
title = "Biscuits and Coffee";
console.log(`[${group}] ${title}: ${difficulty}/3 difficulty`);
export {};
원시 타입을 리터럴 타입으로 고치는 문제.
의도된 오타를 집어넣어서 리터럴 타입의 유용성을 학습하게 하려는 의도가 친절하게 느껴졌다.
728x90
'Typescript > 러닝 타입스크립트 연습문제' 카테고리의 다른 글
(3장 심화) The Narrow Trail (0) | 2023.04.06 |
---|---|
(3장) Primitive Cooking - 3. Seating (0) | 2023.04.06 |
(3장) Primitive Cooking - 1. Ingredients (0) | 2023.04.06 |
(2장) System of a Clown - 2. Clown Availability (0) | 2023.04.06 |
(2장) System of a Clown - 1. Clowning Around (0) | 2023.04.06 |