Open ashubham opened 7 years ago
Any resolution on this?
when es6 suppose will be available? thank you
dts-gen --expression-file "./node_modules/react-native-animatable/index.js"
Unexpected crash! Please log a bug with the commandline you specified.
/usr/local/lib/node_modules/dts-gen/bin/lib/run.js:130
throw e;
^
SyntaxError: Unexpected token import
dts-gen is pretty much useless @msftgits
Is this going to be supported?
Doesn't seem to be working on ES6 modules at all. :( This would be very useful for initial transition from js to ts.
add below to dts-gen-master/lib/run.ts
// @ts-ignore
require("babel-polyfill");
// @ts-ignore
require('babel-register')({
cache: false,
});
and
npm run build
link project to npm
now dts your code by dts-gen -m <your-project-name>
🎉
for expressions
import { transform, TransformOptions } from 'babel-core';
const babelOpt: TransformOptions = {
extends: `${process.cwd()}/.babelrc`,
}
/** ... **/
} else if (args.expression) {
name = args.name || 'dts_gen_expr';
result = guess.generateIdentifierDeclarationFile(name, eval(transform(args.expression, babelOpt).code || ''));
} else if (args['expression-file']) {
if (args.name) throw new ArgsError('Cannot use -name with -expression-file');
const filename = args['expression-file'];
name = path.basename(filename, path.extname(filename)).replace(/[^A-Za-z0-9]/g, '_');
(module as any).paths.unshift(process.cwd() + '/node_modules');
const fileContent = fs.readFileSync(filename, "utf-8");
result = guess.generateIdentifierDeclarationFile(name, eval(transform(fileContent, babelOpt).code || ''));
at least it works for me 🎉
I have a third party library written in ES6, how could I generate typings for this ?