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

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

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

λͺ©λ‘ 보기
23/59

Quiz 1.

/*
[ 문제 μ†Œκ°œ ]
νƒ€μž… 단언을 μ΄μš©ν•΄ person λ³€μˆ˜μ— 빈 객체λ₯Ό ν• λ‹Ήν•˜μ„Έμš”
(힌트. 초과 ν”„λ‘œνΌν‹° 검사 방지λ₯Ό μœ„ν•œ νƒ€μž… 단언)
*/

type Person = {
  name: string;
  age: number;
};

let person: Person = {};

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

let person: Person = {} as Person;

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

Quiz 2.

/*
[ 문제 μ†Œκ°œ ]
νƒ€μž… 단언을 μ΄μš©ν•΄ ν•¨μˆ˜ ν˜ΈμΆœμ—μ„œμ˜ 였λ₯˜λ₯Ό ν•΄κ²°ν•˜μ„Έμš”
(힌트. const 단언)
*/

let value = 10;
giveMe10(value);

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

let value = 10 as const;
giveMe10(value);

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

Quiz 3.

/*
[ 문제 μ†Œκ°œ ]
λ‹€μŒ μš”κ΅¬μ‚¬ν•­μ„ λ§Œμ‘±ν•˜λŠ” μ½”λ“œλ₯Ό μž‘μ„±ν•˜μ„Έμš”
- CompanyMember νƒ€μž…μ„ Boss와 Employee의 μ„œλ‘œμ†Œ μœ λ‹ˆμ˜¨ νƒ€μž…μœΌλ‘œ μ •μ˜ν•˜μ„Έμš”
*/

/* [Quiz] μ•„λž˜μ˜ μ½”λ“œλ₯Ό μ™„μ„±ν•΄ 였λ₯˜λ₯Ό μ œκ±°ν•˜μ„Έμš” */
type Boss = {
  car: string;
};

type Employee = {
  salary: number;
};

type CompanyMember = Employee | Boss;

/* [Test] μ—¬κΈ°λΆ€ν„°λŠ” 정닡을 μ²΄ν¬ν•˜κΈ° μœ„ν•œ μš©λ„λ‘œ μˆ˜μ •ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ */
function test(companyMember: CompanyMember) {
  if (companyMember.type === "Boss") {
    console.log("사μž₯λ‹˜ 또 μ°¨ λ°”κΏ¨λ‹€ : ", companyMember.car);
  } else if (companyMember.type === "Employee") {
    console.log("아직도 월급은 : ", companyMember.salary);
  }
}

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

type Boss = {
  type:"Boss";
  car: string;
};

type Employee = {
  type:"Employee";
  salary: number;
};

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

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

0개의 λŒ“κΈ€