include: 어떤 파일을 컴파일 할것인지
exclude: 어떤 파일을 컴파일 제외 시킬 것인지
"include": ["**/*.ts"], // 모든 폴더의 모든 ts파일을 컴파일 시킴
"exclude": ["node_modules"]
any
number
string
boolean
object
- 객체({})계의 any. 사용 잘 안함
const a: number = 1;
// 오류: const a: number = "hello";
const b: string = 'hi ts';
const c: boolean = true;
처음 선언 시 number로 설정되었기 때문에 string 으로 들어갈 수 없음
let d = 1;
// 오류: d = 'hi'
인터페이스 선언
// 명세, 타입, 클래스를 만들 때
interface IPerson {
name: string;
age: number;
city?: string; // city라는 값을 받을지 안받을지 모를 경우
}
const woman: IPerson = {
name: 'danbi',
age: 25,
city: "seoul"
}
따로 선언하지 않고 타입을 지정해줄 때
const woman: {name: string; age: number; city?: string} = {
name: 'danbi',
age: 25,
city: "seoul"
}
함수에 지정해줄 때
function prt(params: IPerson){
console.log(params?.city ?? "defalut city");
}
prt(woman)
const arr1: number[] = [1, 2, 3] // 주로 사용
const arr2: Array<number> = [1, 2, 3]
const arr3: string[] = ['hi', 'hello', 'world'];
const arr4: Array<string> = ['hi', 'hello', 'world'];
interface IPerson {
name: string;
age: number;
city?: string;
}
const arr5: IPerson[] = [
{
name: 'danbi',
age: 25,
city: "seoul"
},
{
name: 'danbi',
age: 25,
},
...
]
arr5.forEach((e: IPerson) => console.log(e?.city ?? "default"));
튜플 - 배열의 길이 length와 안의 원소를 바꿀 수 없음(불변성 유지)
const arr6: [number, string, object, any[]] = [1, 'hi', {}, []];