본문 바로가기

TypeScript Study3

TypeScript Props 타입 정의 방법, useState * typescript의 ?에 대해서,, 01. 기본개념type Props = { label: string; // 필수 - 반드시 있어야 함 theme?: 'primary'; // 선택 - 있어도 되고 없어도 됨 onPress?: () => void; // 선택 - 있어도 되고 없어도 됨} 02. 예시type Props = { label: string; theme?: 'primary'; // 선택적!}// ✅ 둘 다 정상 // theme 없어도 OK 03. 주의사항선택적 속성의 경우 undefined일 수 있으므로 사용 전 체크 필요함. const UserProfile = ({ name, age, email, phone, onEdit }: UserProfileP.. 2025. 11. 23.
TypeScript 02. 배열과 튜플과 객체 1. 배열 - 배열은 이런식으로 사용한다. const fibonacci : number [] = [0, 1, 1, 2, 3, 5, 8]; const strArr : string [] = ['str', 'arr', 'test']; 2. 튜플 - 튜플은 원소의 수와 타입이 정확히 지정된 배열의 타입을 정의 할 수 있다. 명시된 개수 만큼의 원소를 가질 수 있다. const nameAndHeight : [string, number] = ['strName', 133]; 3.객체 - 객체는 아래와 같이 선언한다. - ? 키워드를 사용할 경우, 해당 속성이 존재하지 않을 수도 있음을 표현 - readonly 키워드를 붙일 경우, 속성의 재할당을 막을 수 있음 -> const //객체 const user : {nam.. 2023. 12. 6.
TypeScript 01. 기본타입 [ 타입스크립트의 기본타입 ] 타입스크립트의 타입을 정의하는 방법은 아래와 같다. 1. boolean type // boolean const isTypeScriptAwesome : boolean = true; const doesJSHasTypees : boolean = false; 2. 숫자 //number const yourScore : number = 100; const ieee7541IsAwesome : number = 0.1 + 0.2; 3. 문자열 //string const authorName : string = 'name'; const toReaders : string = ` n a m e`; 4. null / undefined const nullValue : null = null; const.. 2023. 12. 6.