본문 바로가기
Frontend/TypeScript

[TypeScript] JSDoc

by 민두이 2023. 2. 19.
728x90
반응형

코멘트로 이루어진 문법 

ts 파일이 아닌 js 파일에서 타입을 지정해줄 때에 사용하며,

타입스크립트 문법을 사용하지 않아도 타입스크립트가 자바스크립트 파일을 확인해줌

 

  • 코멘트 생성 방법
//@ts-check
/** + 엔터

ts.config.json 파일 내에 "allowJs":true 추가

{
    "include"  : ["src"],
    "compilerOptions": {
        "allowJs": true
    }
}

 

  • 사용 예시
//@ts-check
/**
 * Initializes the project
 * @param {object} config
 * @param {boolean} config.debug
 * @param {string} config.url 
 * @returns {boolean}
 */

export function init(config) {
    return true;
}

/**
 * Exit the program
 * @param {number} code 
 * @returns  {number}
 */

export function exit(code) {
    return code + 1;
}
728x90