typescript) library의 @types가 존재하지 않을 때 임시방편

김명성·2022년 7월 15일
0

typescript를 사용하여 project를 만들 때, 사용하려는 third party library가 자주 쓰이지 않아 types definition이 없을 때 사용할 수 있는 임시 방편이 있다.

import Highlighter from 'monaco-jsx-highlighter'

monaco-jsx-highlighter는 monaco-editor의 jsx 부분을 highlight 해주는 라이브러리이다.

자주 사용하는 라이브러리가 아니기에, type definition이 npmjs에 등록되어있지 않고 다음과 같은 에러가 출력된다

Try `npm i --save-dev @types/monaco-jsx-highlighter`
if it exists or add a new declaration
(.d.ts) file containing `declare module 'monaco-jsx-highlighter';

npm install을 통해 type definition을 설치하거나, .d.ts 파일을 정의하라는 에러문구가 나온다.

src 폴더에 types.d.ts 파일을 생성한 뒤에 아래와 같이 작성한다.

declare module 'monaco-jsx-highlighter'

0개의 댓글