사용자끼리 이야기할 수 있는 장을 만들기 위해서 사용자의 이름을 바꾸기로 했다. 이를 위해 "str-utils"라는 라이브러리를 쓰기로 했다. 문제는 TS 선언이 없다는 것이다.
node_modules에 있는 라이브러리를 확인해서 declare 해보자.
declare module 'str-utils' {
type StrUtils = {
(value:string):string;
}
export function strReverse: StrUtils; // error 🚨
}
리턴 타입이 StrUtils가 된다.
🔻 공식적인 답안
declare module 'str-utils' {
type StrUtils = {
(value:string):string;
}
export const strReverse: StrUtils;
export const strToLower: StrUtils;
export const strToUpper: StrUtils;
export const strRevestrToUpperrse: StrUtils;
export const strRandomize: StrUtils;
export const strInvertCase: StrUtils;
}
const를 사용한다.