InflearnTS Chapter 1~3 - YDP-SPLOUNGE-CLUB/typescript-study GitHub Wiki
μλ°μ€ν¬λ¦½νΈμμ μ 곡νλ λ°μ΄ν° νμ μ μ§μνλ€.
const a: number = 5;
const b: string = '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 add: Add = (x, y) => x + y;interface νμ μ μ λ°©μ λν μ‘΄μ¬
interface Add {
(x: number, y: number): number;
}
const add: Add = (x, y) => x + y;리μ€νΈν νμ μ μ
// μΌλ° 리μ€νΈ νμ
μ μ
const arr: string[] = ['123', '234'];
// μ λ€λ¦ν 리μ€νΈ νμ
μ μ
const arr2: Array<number> = [123, 345];
// ννν 리μ€νΈ νμ
μ μ
// μμμ ννμ 리μ€νΈ lengthλ₯Ό μ격νκ² μ μ
const arr3: [number, number, string] = [123, 345, 'hello'];μ νν μμκ° νμ μ μ μ κ°λ₯
const t: true = true;tsc --noEmit μμλ νμ μ μΆλ‘ ν΄μ£Όλ κΈ°λ₯λ μ 곡νλ€.
const a = '5';νμ μΆλ‘ μ ν΅ν΄μ λΆνμν νμ μ μλ₯Ό νΌν μ μλ€.
example
κ°μλ₯Ό ν μ¬λμ νμ μ μΆλ‘ μ μ ννκ² μ μκ° λ μνμμλ λ°λ‘ Type μ 건λλ κ²μ μΆμ²νμ§ μμλ€.
const a:string = '5';νμ μΆλ‘ μ κ΅μ₯ν λΆμμ νλ€. μμλ‘
const arr3 = [123, 345, 'hello'];
// ν΄λΉ νμ
μ const arr3: (number | string)[] λ‘ λμ€λλ° ννλ‘ μ νμμ λμ νμ
μΆλ‘ κ³Ό λ§μ§ μλλ€.
// μ΄λ΄ κ²½μ°μλ κΈ°μ‘΄μ μ¬μ©ν ννλ‘ νμ
μ μ μνλ©΄ μ’λ€.
// μμ½. νμ
μΆλ‘ μ μ€ν¨νμλ μ§μ νμ
μ μ ν΄μ£Όλκ²μ΄ κ°μ₯ μμ ν μ μλ€.