728x90
반응형

JSDoc : comment로만 이루어진 문법으로 이를 이용하여 js 파일에 ts 문법을 적용할 수 있다.

적용 조건 : tsconfig.json에 "allowJs": true  추가

함수 바로 위에 코멘트를 작성하는 방식으로 

js파일 위에 // @ts-check을 작성하면 js에서도 타입을 지정할 수 있다.

 

// @ts-check
/**
 * Intializes the project
 * @param {object} config 
 * @param {boolean} config.debug
 * @param {string} config.url
 * @returns boolean
 */

export function init(config) {
  return true;
}

/**
 * Exits the program
 * @param {number} code 
 * @returns number
 */
export function exit(code) {
  return code + 1;
}
728x90
반응형

'IT > Typescipt' 카테고리의 다른 글

Typescript 프로젝트 설정  (0) 2022.11.06
Typescript Classes, Interface  (0) 2022.11.06
Typescript Functions - Polymorphism 다형성  (0) 2022.11.05

+ 최근 게시글