zackradisic/node-soundcloud-downloader

Error when compiling

Closed this issue · 10 comments


8   const trackNames = []
          ~~~~~~~~~~

node_modules/soundcloud-downloader/src/download-playlist.ts:10:24 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

10     const p = download(track.permalink_url, clientID, axiosInstance)
                          ~~~~~~~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/download-playlist.ts:15:19 - error TS7005: Variable 'trackNames' implicitly has an 'any[]' type.

15   return [result, trackNames]
                     ~~~~~~~~~~

node_modules/soundcloud-downloader/src/download.ts:91:29 - error TS2532: Object is possibly 'undefined'.

91   return await fromMediaObj(info.media.transcodings[0], clientID, axiosInstance)
                               ~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:1:19 - error TS7016: Could not find a declaration file for module 'soundcloud-key-fetch'. 'D:/Bernd/BerndPC/Documents/Github/Javascript/Discord-MusicBot/node_modules/soundcloud-key-fetch/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/soundcloud-key-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'soundcloud-key-fetch';`

1 import sckey from 'soundcloud-key-fetch'
                    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:24:32 - error TS2532: Object is possibly 'undefined'.

24   const filtered = filterMedia(info.media.transcodings, { format: format })
                                  ~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:51:3 - error TS2564: Property 'STREAMING_PROTOCOLS' has no initializer and is not definitely assigned in the constructor.

51   STREAMING_PROTOCOLS: { [key: string]: STREAMING_PROTOCOLS }
     ~~~~~~~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:52:3 - error TS2564: Property 'FORMATS' has no initializer and is not definitely assigned in the constructor.        

52   FORMATS: { [key: string]: FORMATS }
     ~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:57:3 - error TS2564: Property 'axios' has no initializer and is not definitely assigned in the constructor.

57   axios: AxiosInstance
     ~~~~~

node_modules/soundcloud-downloader/src/index.ts:247:5 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

247     return this._clientID
        ~~~~~~~~~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:274:7 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

274       return this._clientID
          ~~~~~~~~~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/index.ts:287:7 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(path: number | PathLike, options: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined, callback: (err: ErrnoException | null, data: Buffer) => void): void', gave the following error.
    Argument of type '"utf8"' is not assignable to parameter of type '{ encoding?: null | undefined; flag?: string | undefined; } | null | undefined'.
  Overload 2 of 4, '(path: number | PathLike, options: string | { encoding: string; flag?: string | undefined; }, callback: (err: ErrnoException | null, data: string) => void): void', gave the following error.
    Argument of type '(err: NodeJS.ErrnoException, data: string) => void' is not assignable to parameter of type '(err: ErrnoException | null, data: string) => void'.
      Types of parameters 'err' and 'err' are incompatible.
        Type 'ErrnoException | null' is not assignable to type 'ErrnoException'.
          Type 'null' is not assignable to type 'ErrnoException'.
  Overload 3 of 4, '(path: number | PathLike, options: string | { encoding?: string | null | undefined; flag?: string | undefined; } | null | undefined, callback: (err: ErrnoException | null, data: string | Buffer) => void): void', gave the following error.
    Argument of type '(err: NodeJS.ErrnoException, data: string) => void' is not assignable to parameter of type '(err: ErrnoException | null, data: string | Buffer) => void'.
      Types of parameters 'err' and 'err' are incompatible.
        Type 'ErrnoException | null' is not assignable to type 'ErrnoException'.
          Type 'null' is not assignable to type 'ErrnoException'.

287       fs.readFile(filename, 'utf8', (err: NodeJS.ErrnoException, data: string) => {
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288         if (err) return reject(err)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
309         }
    ~~~~~~~~~
310       })
    ~~~~~~~~


node_modules/soundcloud-downloader/src/index.ts:322:31 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

322       if (isFirebaseURL(url)) url = await convertFirebaseURL(url, this.axios)
                                  ~~~

node_modules/soundcloud-downloader/src/info.ts:168:24 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'never'.

168       splitIds[i].push(ids[x])
                           ~~~~~~

node_modules/soundcloud-downloader/src/likes.ts:43:23 - error TS2532: Object is possibly 'undefined'.

43   while (nextHref && (options.limit > 0 || options.limit === -1)) {
                         ~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/likes.ts:53:89 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'Like' is not assignable to parameter of type 'ConcatArray<never>'.
      Type 'Like' is missing the following properties from type 'ConcatArray<never>': length, join, slice
  Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'Like' is not assignable to parameter of type 'ConcatArray<never>'.

53     query.collection = query.collection.reduce((prev, curr) => curr.track ? prev.concat(curr) : prev, [])
                                                                                           ~~~~


node_modules/soundcloud-downloader/src/likes.ts:54:10 - error TS2454: Variable 'response' is used before being assigned.

54     if (!response) {
            ~~~~~~~~

node_modules/soundcloud-downloader/src/likes.ts:63:7 - error TS2532: Object is possibly 'undefined'.

63       options.limit -= query.collection.length
         ~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/likes.ts:65:11 - error TS2532: Object is possibly 'undefined'.

             ~~~~~~~~~~~~~

node_modules/soundcloud-downloader/src/likes.ts:79:10 - error TS2454: Variable 'response' is used before being assigned.

79   return response
            ~~~~~~~~


Found 20 errors.```

This is the error log from tsc

Hi, if you are using this in your project you can set compilerOptions.skipLibCheck to true and this will not type check this lib.

@zackradisic It is set to true and still throws errors. i have "skipLibCheck": true, in my tsconfig

@kaaax0815 Ok try importing the lib like this:

import scdl from 'soundcloud-downloader/dist/index'

This will force import of the transpiled JavaScript, instead of the Typescript you will have to compile. This is not an ideal solution and I'm working on v2.0.0 which fixes these problems. Please let me know if you still have problems

@zackradisic Could not find a declaration file for module 'soundcloud-downloader/dist/index'. 'd:/Bernd/BerndPC/Documents/Github/Javascript/Discord-MusicBot/node_modules/soundcloud-downloader/dist/index.js' implicitly has an 'any' type. Try `npm i --save-dev @types/soundcloud-downloader` if it exists or add a new declaration (.d.ts) file containing `declare module 'soundcloud-downloader/dist/index';

But normally only the transpiled javascript gets shipped anyway, so is it for most packages

@zackradisic Do you have any support patch until 2.0.0

@kaaax0815 Yeah forgot to mention that importing the transpiled JavaScript means you won't get any typings, and you'll have to declare the module in a .d.ts file. This is probably the best option for right now.

If you still want typings for intellisense, I'm working on v2.0.0 on the v2.0.0 branch. You can install the module directly from there npm install zackradisic/node-soundcloud-downloader#v2.0.0. I can't quite remember, but I think I fixed the type errors there. Just keep in mind that I'm developing on this branch and so I'm likely going to be introducing breaking changes.

@zackradisic okay ill go with the custom decleration. but i would recommend you only ship the js with the decleration. that is what most do. but thanks for your help

@zackradisic Do you have a full declaration? because if i import it from the typescript path I get errors again. And If i declare an empty module everything is 'any' which defeats the whole purpose of typescript

Edit:

With:

dts-bundle --name "soundcloud-downloader/dist" --main .\dist\index.d.ts

I get the generall structure but i had to import the Typings from src and then would get errors
So I now what functions want as arguments and the response type but not the typings itself

Edit2:

I am wrong I get typing but no errors. I dont know how and why but it works as expected

Yeah so the declarations file was lazily made and imports the .ts files, which does not help your problem 😅

Have never heard of dts-bundle, but it seems to have done the job, nice find!

Why do you need to make a own declaration? in my projects the tsc declaration is perfectly fine