microsoft / dts-gen

dts-gen creates starter TypeScript definition files for any module or library.
MIT License
2.43k stars 101 forks source link

Browser bundle: TypeError: e is null #160

Open foo123 opened 4 years ago

foo123 commented 4 years ago

I am trying to use dts-gen and most importantly the browser bundle (since I have libraries which are not npm packages) to generate a starting point d.ts for the following lib of mine (Abacus).

What I do is use the browser bundle (from a local install) and load the script of the lib and generate the dts giving the Abacus identifier in popup window.

See screenshot below:

Snap 2020-05-17 at 20 02 52

dts-gen browser bundle fails with TypeError: e is null. Abacus is a plain object which should be declared as a namespace in d.ts. If i try to dts-gen a specific class of Abacus namespace, eg Polynomial = Abacus.Polynomial, it works but fior some reason fails to process Abacus top object which works as a namespace.

Am I doing sth wrong? Any way to use dts-gen for custom plain js files which are not npm packages?

Please advise..

foo123 commented 4 years ago

When I try to make dts-gen command line process the same lib where I have simulated local node_modules and try to load it as a module I get following error:

dts-gen -m Abacus > Abacus.d.ts
C:\Users\User\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\run.js:125
        throw e;
        ^

TypeError: Cannot read property 'prototype' of null
    at isClasslike (C:\Users\User\AppData\Roaming\npm\node_modules\dts-gen\bin\l
ib\index.js:109:19)
    at getKeysOfObject.some.k (C:\Users\User\AppData\Roaming\npm\node_modules\dt
s-gen\bin\lib\index.js:42:41)
    at Array.some (<anonymous>)
    at hasCloduleProperties (C:\Users\User\AppData\Roaming\npm\node_modules\dts-
gen\bin\lib\index.js:42:31)
    at getValueTypes (C:\Users\User\AppData\Roaming\npm\node_modules\dts-gen\bin
\lib\index.js:30:37)
    at getResult (C:\Users\User\AppData\Roaming\npm\node_modules\dts-gen\bin\lib
\index.js:187:55)
    at getTopLevelDeclarations (C:\Users\User\AppData\Roaming\npm\node_modules\d
ts-gen\bin\lib\index.js:124:17)
    at Object.generateModuleDeclarationFile (C:\Users\User\AppData\Roaming\npm\n
ode_modules\dts-gen\bin\lib\index.js:50:19)
    at Object.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\dts-ge
n\bin\lib\run.js:58:24)
    at Module._compile (internal/modules/cjs/loader.js:689:30)