TIL( TypeScriptํ์ต )
2024. 6. 27. 23:23ใTIL
๐ก์ธํ๋ฐ ๊ฐ์์์ : ํ์ ์คํฌ๋ฆฝํธ ์ฌ์ธ์ (๋ฌธ๋ฒํธ)
1. ๊ธฐ๋ณธ ํ์ ์ง์
const a = '5'; // const๋ ๊ฐ์ด ์ง์ ๋๊ธฐ ๋๋ฌธ์ ๊ตณ์ด :string์ผ๋ก ํ์
์ ํ๋ฒ๋ ์ง์ ํด์ค ํ์๊ฐ ์๋ค.
const b = 5; // const b:number = 5;
const c = undefined; // const c:undefined = undefinded
const d = true; // const d:boolean = true;
const e = null; // const e:null = null;
2. ํ์ ์ ๊ณ ์ ๋ ๊ฐ ์ง์
//ํ์
์ ๊ณ ์ ๋ ๊ฐ ์ง์ ๊ฐ๋ฅ (ํ์
์ ํญ์ ์ ํํด์ผํ๋ค.)
const f: true = true;
const g: 2 = 2;
3. ํจ์ ์์ฑํ๋ ๋ฐฉ๋ฒ
function add(x:number, y:number): number {return x + y};
const result = add( 1,5)
const add: (x:number, y:number) => number = (x, y) => x + y;
interface Add {
(x:number, y: number): number;
}
const add: Add = (x, y) => x + y;
4.๋ฐฐ์ด ๊ณผ ํํ ํ์ ์ง์
const arr: string[] = ['123','345']
const arr2: number[] = [123, 234]
const arr3: Array<number> = [123, 345] // < > => ์ ๋ค๋ฆญ์ด๋ผ๊ณ ํ๋ค.
const arr4: [number, number, string] = [123, 566, '456'] //ํํ์ด๋ผ๋ ๋ฐฉ๋ฒ์ ๊ฐฏ์๊น์ง ์ง์ ๋จ
5. ๊ฐ์ฒด ํ์ ์ง์
const obj: { lat: number, lon: number} = {lat: 37.5, lon: 127.5}
====
const obj = {lat: 37.5, lon: 127.5}
** ์ฝ์ด๋ณผ ๋ฌธ์
TypeScript: Handbook - The TypeScript Handbook (typescriptlang.org)
Handbook - The TypeScript Handbook
Your first step to learn TypeScript
www.typescriptlang.org
TypeScript: Documentation - TypeScript 5.5 (typescriptlang.org)
Documentation - TypeScript 5.5
TypeScript 5.5 Release Notes
www.typescriptlang.org
'TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
TIL ( ๋ฐ์ฝ๋ ์ดํฐ - ts ) (0) | 2024.07.01 |
---|---|
TIL ( prisma ์์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค(MySQL) ์ฐ๊ฒฐํ๊ธฐ ) (0) | 2024.06.28 |
TIL ( TypeScript ํ์ต) (0) | 2024.06.26 |
TIL ( WebSocket ) (0) | 2024.06.25 |
TIL (class) (0) | 2024.06.24 |