I am currently working on fixing the Typescript declaration for youtube-dl-exec. This library has a default export that is a function with properties. Essentially, the default export returns a promise, but alternatively, you can use the exec()
method which returns a child process allowing you to monitor progress without waiting for the promise to resolve.
The current declaration functions correctly for the default function, but not for any of the properties:
import ytdl from 'youtube-dl-exec';
const p = ytdl('https://example.com'); // p is Promise<YtResponse>
const r = ytdl.exec('https://example.com'); // r should be ExecaChildProcess
// ^ property exec does not exist … ts(2339)
My proposed declaration so far is as follows:
declare module 'youtube-dl-exec' {
type ExecaChildProcess = import('execa').ExecaChildProcess;
const youtubeDl = (url: string, flags?: YtFlags, options?: Options<string>) => Promise<YtResponse>;
youtubeDl.exec = (url: string, flags?: YtFlags, options?: Options<string>) => ExecaChildProcess;
export default youtubeDl;
}
Currently, Typescript recognizes the existence and signature of exec
, but assigns the return type as 'any'. Even if I change the return type to a primitive string
, the Typescript compiler still identifies the return type of exec
as 'any.'
Despite getting close with assigning the function property, I am struggling to specify the return type of this function property.