[ν•œμž…] πŸ“’Day11 Quiz

TKΒ·2023λ…„ 12μ›” 17일
0

[κ°•μ˜] ν•œμž… μ‹œλ¦¬μ¦ˆ

λͺ©λ‘ 보기
46/59

Quiz 1.

/*
[ 문제 μ†Œκ°œ ]
λ‹€μŒ μš”κ΅¬μ‚¬ν•­μ„ λ§Œμ‘±ν•˜λŠ” 3개의 μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•˜μ„Έμš”
1. Content Interface
  - name(String νƒ€μž…), info(T νƒ€μž…) ν”„λ‘œνΌν‹°λ₯Ό κ°–μŠ΅λ‹ˆλ‹€.
2. Video Interface
  - playTime(Number νƒ€μž…) ν”„λ‘œνΌν‹°λ₯Ό κ°–μŠ΅λ‹ˆλ‹€. 
3. Book Interface
  - pageNumber(Number νƒ€μž…) ν”„λ‘œνΌν‹°λ₯Ό κ°–μŠ΅λ‹ˆλ‹€.
*/

/* [Quiz] μ•„λž˜μ˜ μ½”λ“œλ₯Ό μˆ˜μ •ν•˜μ„Έμš” */

interface Video {}

interface Book {}

interface Content {}

/* [Test] μ—¬κΈ°λΆ€ν„°λŠ” 정닡을 μ²΄ν¬ν•˜κΈ° μœ„ν•œ μš©λ„λ‘œ μˆ˜μ •ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ */
function watchVideo(content: Content<Video>) {
  console.log(`${content.info.playTime}μ‹œκ°„μ˜ κ°•μ˜λ₯Ό μ‹œμ²­ν•¨`);
}

function readBook(content: Content<Book>) {
  console.log(`${content.info.pageNumber}ꢌ의 책을 읽음`);
}

watchVideo({
  name: "ν•œ μž… 크기둜 μž˜λΌλ¨ΉλŠ” νƒ€μž…μŠ€ν¬λ¦½νŠΈ",
  info: {
    playTime: 10.5,
  },
});

readBook({
  name: "ν•œ μž… 크기둜 μž˜λΌλ¨ΉλŠ” λ¦¬μ•‘νŠΈ",
  info: {
    pageNumber: 700,
  },
});

βœοΈλ‹΅μ•ˆ

interface Video {
  playTime: number;
}

interface Book {
  pageNumber: number;
}

interface Content<T> {
  name: string;
  info: T;
}

μ½”λ“œλ§ν¬

Quiz 2.

/*
[ 문제 μ†Œκ°œ ]
getComments ν•¨μˆ˜μ˜ μ μ ˆν•œ λ°˜ν™˜κ°’ νƒ€μž…μ„ μ •μ˜ ν•˜μ„Έμš”
- getComments ν•¨μˆ˜λŠ” μ—¬λŸ¬κ°œμ˜ Comment νƒ€μž… 객체λ₯Ό λ‹΄λŠ” 배열을 λΉ„λ™κΈ°μ μœΌλ‘œ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
- λ°˜ν™˜κ°’ νƒ€μž…μ΄ Promise<unknown>이 μ•„λ‹Œ μ’€ 더 μ •ν™•ν•œ νƒ€μž…μœΌλ‘œ μΆ”λ‘ λ˜κ²Œ ν•˜μ—¬λ„ μ •λ‹΅μœΌλ‘œ μΈμ •ν•©λ‹ˆλ‹€.
*/

/* [Quiz] μ•„λž˜μ˜ μ½”λ“œλ₯Ό μˆ˜μ •ν•˜μ„Έμš” */
interface Comment {
  id: number;
  author: string;
  content: string;
}

function getComments() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve([
        {
          id: 1,
          author: "μ΄μ •ν™˜ & κΉ€νš¨λΉˆ",
          content: "ν•œμž… FE μ±Œλ¦°μ§€! μ™„κ°•κΉŒμ§€ ν™”μ΄νŒ…!",
        },
      ]);
    }, 2000);
  });
}

/* [Test] μ—¬κΈ°λΆ€ν„°λŠ” 정닡을 μ²΄ν¬ν•˜κΈ° μœ„ν•œ μš©λ„λ‘œ μˆ˜μ •ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ */
import { Equal, Expect, NotEqual } from "@type-challenges/utils";

type TestCases = [
  Expect<NotEqual<ReturnType<typeof getComments>, Promise<any>>>,
  Expect<NotEqual<ReturnType<typeof getComments>, Promise<unknown>>>,
  Expect<NotEqual<ReturnType<typeof getComments>, Promise<never>>>,
  Expect<Equal<ReturnType<typeof getComments>, Promise<Comment[]>>>
];

βœοΈλ‹΅μ•ˆ

function getComments():Promise<Comment[]> {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve([
        {
          id: 1,
          author: "μ΄μ •ν™˜ & κΉ€νš¨λΉˆ",
          content: "ν•œμž… FE μ±Œλ¦°μ§€! μ™„κ°•κΉŒμ§€ ν™”μ΄νŒ…!",
        },
      ]);
    }, 2000);
  });
}

μ½”λ“œλ§ν¬

profile
μ‰¬μš΄κ²Œ 쒋은 FE개발자😺

0개의 λŒ“κΈ€