I am trying to create a Typescript definition file for format-duration:
module.exports = (ms) => {
let { days, hours, minutes, seconds } = parseMs(ms)
seconds = addZero(seconds)
if (days) return `${days}:${addZero(hours)}:${addZero(minutes)}:${seconds}`
if (hours) return `${hours}:${addZero(minutes)}:${seconds}`
return `${minutes}:${seconds}`
}
I have tried a few different declaration files:
export default function (ms: number): string;
export default function formatDuration(ms: number): string;
export function formatDuration(ms: number): string;
and whilst I do get the correct type information from them when I run the application I get an error:
import formatDuration from "format-duration";
const formatted = formatDuration(123456);
Exception has occurred: TypeError
TypeError: format_duration_1.default is not a function
How do I properly define types for this sort of javascript library?
declare formatDuration:(ms:number):string