본문 바로가기

Front-End/TypeScript

TypeScript #6 (예제로 보는 모듈 맛보기)

반응형

예제

 

.src/utils/makePerson.ts

export function makePerson (name: string, age: number) {
    return {name, age};
}


export function testMakePerson () {
    console.log(
        makePerson("Jane", 22),
        makePerson("Jack", 33),
    )
}

 

 

.src/index.ts

import { testMakePerson } from "./utils/makePerson";

testMakePerson();

 

 

 

 

 

 

 

 

ts-node ./src/index.ts 명령을 사용하지만, index.ts 파일 한정으로 ts-node ./src 로 실행 가능

ts-node ./src

 

 

 

 

 

 

반응형

'Front-End > TypeScript' 카테고리의 다른 글

TypeScript #8 (클래스 실습)  (2) 2025.07.02
TypeScript #7 (타입 연습 문제)  (0) 2025.07.02
TypeScript #5 (클래스)  (0) 2025.07.01
TypeScript 기초 #4 (타입)  (0) 2025.07.01
TypeScript 기초 #3 (TS에서 쓰는 문법들)  (0) 2025.07.01