enum타입을 간단히 한 코드는 무엇인가?
A)
const users = ['Max', 'Michael', 'Julie'];
B)
const userA = { name: 'Max' }; const userB = { name: 'Michael' };
C)
const ROLE_ADMIN = 0; const ROLE_AUTHOR = 1;
정답 : C
컴파일 에러를 낼까요?
type User = {name: string; age: number}; const u1: User = ['Max', 29];
답 : yes
Correct! The "User" type clearly wants an object with a "name" and an "age" property. NOT an array.
컴파일 할 수 있나요?
type Product = {title: string; price: number;}; const p1: Product = { title: 'A Book', price: 12.99, isListed: true }
답 : No
isListed is not part of the "Product" type.
컴파일 할 수 있나요?
type User = { name: string } | string; let u1: User = {name: 'Max'}; u1 = 'Michael';
답: YES
This code is fine. The union type allows either an object (with a "name" property) OR a string. You can switch values how often you want.
유니온타입.
객체와 문자열 모두 타입으로 정할 수 있다.