phenomejs / phenome

The ultimate cross-framework component compiler
http://phenomejs.org
MIT License
71 stars 8 forks source link

Minimal typescript props, events, methods #39

Closed JasonKleban closed 6 years ago

JasonKleban commented 6 years ago

Cool! Here's some of it filled in.

I didn't attempt to convert prop types into appropriate typescript types. I'm skeptical that there is enough fidelity in this least-common-denominator type system - like, when we're getting back a Route or a View, react-proptypes will only represent that as an Object, right? And it would be nice to include the jsdoc documentation for each thing, mirroring what you have in the online docs for F7 about each component.

Good point about abstracting from F7. There are quite a few features like the core App component, the app-level extensions to it by each component's concerns, and reused F7 core types - if Phenome is agnostic, can it accommodate the core api somehow?

To save you the suspense, here's the generated output. Again, there's more type information in your AST than is represented yet, but we need a mechanism for converting its prop types to the most appropriate typescript type:

namespace MyPhenomeComponent {
  export interface Props {
      foo? : any
      bar? : any
      fooBar? : any
      one : any
      two? : any
      onComponentOpen? : Function
      onComponentClose? : Function
  }
}
export class MyPhenomeComponent extends React.Component<MyPhenomeComponent.Props, {}> {
  open(animate : any) : unknown
  close(animate : any) : unknown
}

You don't have to really pull this in to your branch, a PR just seemed to be the easiest way to share it.

JasonKleban commented 6 years ago

https://github.com/phenomejs/phenome/issues/11

nolimits4web commented 6 years ago

Looks good, thanks! I’ll have more time next week to tweak compiler to save generated ts files