joarwilk / typedef-converter Goto Github PK
View Code? Open in Web Editor NEWConverts typescript definition files to flowtype library files
License: Other
Converts typescript definition files to flowtype library files
License: Other
Would adding tests for this project be a welcome contribution?
Some libraries I'd like to consume in our TS app are written in flow-type, or expose flow-type definitions. I'd also prefer not to write duplicate type definitions. :simple_smile:
How difficult would it be to translate in the other direction? I've seen some people discuss this but haven't found any projects that work or are actively maintained.
Would it require a very different codebase to convert in the opposite direction? Or only a simple PR? If you think it won't be a lot of work I'd be happy to take a stab at it.
Some definitions have nested modules that looks like this:
declare module 'Outer' {
declare module 'inner {
interface nestedInterface {
member: any
}
}
}
Nested modules currently get flattened and all inner modules are put in global scope, which will cause issues (most inner modules have very generic names which could overwrite definitions for other modules).
When using a .d.ts file to declare global interfaces, e.g.:
interface AttrDef {
propName: string;
}
the converter will produce:
declare module 'root' {
declare interface AttrDef {
propName: string
}
}
Is is possible to produce just:
declare interface AttrDef {
propName: string
}
The root module shouldn't have any children, instead different files should put their root nodes in a module with the same name as the file.
Hey, would you be willing to maintain this works with MobX (mobxjs/mobx#640) and support the official flow types?
Right now it doesn't check for import declarations. There's a system in place for inserting them into the tree, normalizing and printing them but the parser doesn't do the proper check.
To implement this, the parser should be modified collect import nodes.
When storing nodes in the node ref cache, nodes are stored by name/kind/context, so any subsequent node with the same props overrides any previous node (see: lodash).
Should probably store nodes by some random unique id instead, but then it becomes impossible to fetch from the store without knowing the ID. That might be a good thing, though.
Comments are available in the *leadingComments property on the node, should be possible to retain the comment for later print.
This is an awesome tool! Thanks for making this, I've been able to convert some large but simple definitions from DT, saving me hours of work!
I ran into a problem when trying to convert blessed:
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/blessed/blessed.d.ts
/usr/local/lib/node_modules/typedef-converter/lib/printer.js:221
var heritage = node.heritageClauses.map(function (clause) {
^
TypeError: Cannot read property 'map' of undefined
at printClass (/usr/local/lib/node_modules/typedef-converter/lib/printer.js:221:38)
at Array.map (native)
at /usr/local/lib/node_modules/typedef-converter/lib/printer.js:270:415
at Array.map (native)
at finalPrint (/usr/local/lib/node_modules/typedef-converter/lib/printer.js:269:6)
at Command.program.version.arguments.option.action (/usr/local/lib/node_modules/typedef-converter/index.js:31:46)
at Command.listener (/usr/local/lib/node_modules/typedef-converter/node_modules/commander/index.js:301:8)
at emitOne (events.js:96:13)
at Command.emit (events.js:188:7)
at Command.parseArgs (/usr/local/lib/node_modules/typedef-converter/node_modules/commander/index.js:617:12)
When converting the definition file like following
export declare function isNumeric(val: any): val is number;
./lib/printer.js
throw error.
Probably, TypeScript's BasicTypes(like number, string, boolean...) hasn't typeName
.
// lib/printer.js
var printType = function printType(type) {
if (Types[type.kind]) {
return Types[type.kind];
} else {
switch (type.kind) {
...
case 'TypePredicate':
// throw error, when predicate function return type predicate.
return type.type.typeName.text;
// As workaround, I avoid access to typeName like following.
// return type.type.typeName ? type.type.typeName.text : Types[type.type.kind];
Namespaces converted to modules should export all fields as a default export.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.