Open csuarezgfx opened 7 years ago
I'm not sure what this means. Can you sketch out what the behavior should be?
Sure, I'd like to generate typescript definition file for a single javascript file. So if I could
dts-gen
Maybe you could give an example of an input JS file and an output .d.ts file from this process?
ok. I have a collada loader in my node_modules folder which consists of only one file. threejs-collada-loader I'd like to generate a .d.ts file for it. That is what dts-gen does correct?
+1 for this
+1
+1
I got a workaround by doing the following:
yourObj.toSource()
(toSource is only available on Firefox)yourlib.js
dts-gen --expression-file yourlib.js
@RyanCavanaugh What is needed here is a way to call dts-gen jquery.js -expr $ --out jquery.d.ts
for example, and dts-gen would load jquery.js
, look at the $
object and generate the jquery.d.ts out of that.
+1, I have an UMD module generated through browserify. For some reason I had to include both enzyme and react in the UMD module. In my typescript I imported this UMD module, everything works fine except intellisense is not working. I guess .d.ts will help here and it would be helpful if tool can get declaration from the UMD module.
+1
+1
+1e6
👍 A lot of packages are not npm packages, so you can't install them as a module!
Running this gives: Couldn't load module "undefined". Please install it globally (npm install -g undefined) and try again.
dts-gen --expression-file yourlib.js
I have a lib that is a module but not an npm package so I try to generate .d.ts with dts-gen via an expression:
dts-gen -e "require('lib.js')" -f lib.d.ts
but I get the error:
Couldn't load module "undefined". Please install it globally (npm install -g undefined) and try again.
I though that requiring the lib as an expression would work. So a way is needed to be able to gen dts files from a file that IS NOT an installed npm package.
So +1 for a solution to this
Yea, it's annyoing. I should generate the d.ts of leaflet-draw. First it complains about window and document not being defined. Great, because leaflet is not a nodejs module, and browser-only libraries are so rare, especially with JS.
Another great thing is, I now declare
var window = window || {};
var document = document || {};
on top of the file, and now it complains about Leaflet not being defined.
Then I define it
var L = L || {};
and now it complains about L.drawLocal.extend
Cannot read property "extend" of undefined.
Sure a "very" utilizable tool.
It's a good thing after all, that the files in DefinitelyTyped are not up-to-date, so TypeScript becomes an unproductivity tool. The rod between the wheels, so to say.
And cool, now I finally got it to work:
npm install -g leaflet
edit leaflet and leaflet-draw to have this on the top, path of leatlet is as per error message in /root/.nvm/versions/node/v14.3.0/lib/node_modules/leaflet/dist/leaflet-src.js
const Window = require('window');
const window = new Window();
const navigator = require('navigator');
const { JSDOM } = require('jsdom');
const DEFAULT_HTML = '<html><body></body></html>';
const jsdom = new JSDOM(DEFAULT_HTML, {
url: "https://www.bbc.co.uk",
referrer: "https://www.bbc.co.uk",
contentType: "text/html",
userAgent: "node.js",
includeNodeLocations: true
});
const document = jsdom.window.document;
const L= require('leaflet'); // in leaflet-draw only.
dts-gen --expression-file ./leaflet.draw-src.js
and we now have the "resounding" victory of a file "leaflet_draw_src.d.ts" generated, with content
/** Declaration file generated by dts-gen */
declare const leaflet_draw_src: any;
Ahahaha. It would be funny, if I wouldn't need it.
3 Years now, is there any progress? Because there are still people like me who need that
Have some news to ignore required files?
I fixed the issue in #168. We should wait until someone merges it.
What's the progress here?
I have published my PR until it is merged:
npm install -g @aminya/dts-gen
dts-gen --expression-file=./your_file.js
with an option to specify an output directory and name?
Thanks