프로젝트: 인벤토리 항목
Coddy Lua 여정의 Luau 소개 섹션에 포함된 레슨 — 73개 중 63번째.
챌린지
쉬움핵심 타입과 두 개의 아이템을 정의하여 인벤토리 프로젝트를 시작하세요.
id: number,name: string그리고data: T필드를 갖는 제네릭 타입 별칭Item<T>를 선언하세요.id = 1,name = "Iron Sword"및data = {damage = 25}를 갖는Item<{damage: number}>타입의sword를 생성하세요.id = 2,name = "Health Potion"및data = {heal = 40}을 갖는Item<{heal: number}>타입의potion을 생성하세요.
그런 다음, 각각 한 줄에 하나씩 출력하세요:
sword.idsword.namesword.data.damagepotion.idpotion.namepotion.data.heal
직접 해보기
-- 여기에 코드를 작성하세요
-- 1) id, name, data를 가진 제네릭 타입 Item<T>를 선언하세요
-- 2) sword (Item<{damage: number}>)와 potion (Item<{heal: number}>)을 생성하세요
-- 3) 요청된 여섯 개의 필드를 한 줄에 하나씩 출력하세요