Giter VIP home page Giter VIP logo

typedef-converter's People

Contributors

joarwilk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

typedef-converter's Issues

PR: Adding tests

Would adding tests for this project be a welcome contribution?

Any chance of supporting the other direction? (flow => .d.ts)

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.

Support nested modules

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).

support for global declarations

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
}

MobX

Hey, would you be willing to maintain this works with MobX (mobxjs/mobx#640) and support the official flow types?

Import declarations are not collected

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.

Nodes that share name, kind and scope override each other

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 not preserved

Comments are available in the *leadingComments property on the node, should be possible to retain the comment for later print.

fails on blessed from DT

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)

Support type predicate with BasicTypes

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];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.