● 타입스크립트 기본
// 타입은 소문자로 적어주고, 변수 뒤에 위치
const a: string = '5';
const b: number = 5;
const c: boolean = true;
const d: undefined = undefined;
const e: null = null;
function add(x: number, y: number): number {
return x + y;
}
const add2: (x: number, y: number) => number = (x, y) => x + y;
type Add = (x: number, y: number) => number;
const add3: Add = (x, y) => x + y;
interface Add2 {
(x: number, y: number): number;
}
const add4: Add2 = (x, y) => x + y;
const obj: { lat: number; lon: number } = { lat: 37.5, lon: 127.5 };
const arr: string[] = ["123", "456"];
// <number>은 제네릭
const arr2:Array<number> = [123,456]
// 튜플 : 타입과 수가 정해져있음
const arr3:[number, number, string] = [123,456,'hello']
'Language > TypeScript' 카테고리의 다른 글
union(|)과 intersection(&) (0) | 2023.02.09 |
---|---|
enum, keyof, typeof (0) | 2023.02.07 |
원시 래퍼 타입, 템플릿 리터럴 타입, rest, 튜플 (0) | 2023.02.05 |
never 타입과 느낌표 (0) | 2023.02.04 |
JS 변환 시 사라지는 부분 (0) | 2023.02.02 |