Following from my previous post, I've updated the function to use only the path module. Now, the code looks like:
export function changeExtension(filepath: string, extension: string): string {
let dir: string = path.dirname(filepath)
let ext: string = path.extname(filepath)
let root: string = path.basename(filepath, ext)
ext