Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Type providers #722

Open
samwgoldman opened this issue Aug 15, 2015 · 9 comments
Open

Feature request: Type providers #722

samwgoldman opened this issue Aug 15, 2015 · 9 comments

Comments

@samwgoldman
Copy link
Member

It would be really cool to be able to create types from something other than inference/annotations at compile time. In particular, I can think of two use cases:

  1. JSON Schema. It would be really interesting if we could write a type-level function schema(schema: string) -> type, which would take a JSON schema document and output a type. This capability would allow us to use the same schema document on the server/other contexts, while keeping the type checking in sync automatically. We might want to make the argument a path, or have a separate builtin type-level function to read files.
  2. Tagged templates. Currently, tagged templates are pretty smart already, but there's opportunity here too. In particular, I'm thinking of the Relay.QL tagged template.

For nuts and bolts, I was thinking that we could use something like OCaml's Dynlink, so the providers would be OCaml bytecode, which would register their capabilities with some builtin API.

@eyyub
Copy link
Contributor

eyyub commented Aug 16, 2015

Great idea ! F# users love this feature !
Using dynlink is suitable, even if it's pretty low level (You could take a look to ocaml_plugin if you want to see something easier to use).

@aaronshaf
Copy link

It’d be nice if flow understood JSON Schema. Less need to double up on schema/interface declarations.

@STRML
Copy link
Contributor

STRML commented Dec 2, 2015

This would be a huge help. The opposite already exists (https://github.com/seanhess/runtime-types) for converting Flow types to simple JSON. I may start work on a very simple POC that reverses the process - we download schemata from a database on boot and I'd really like to work it into our build process so we can validate everything flowing through the system.

@jefffriesen
Copy link

@STRML Any progress on converting JSON schema to Flow types?

@STRML
Copy link
Contributor

STRML commented Jun 24, 2016

Yeah, I have a project working with https://github.com/STRML/json-to-flow. You can create your own templates & hooks if you need custom functionality.

@vkurchatkin vkurchatkin mentioned this issue Nov 16, 2016
16 tasks
@asolove
Copy link
Contributor

asolove commented Aug 28, 2017

Just wanted to check in on whether anyone had made progress or explored this. I'm very interested in a standard way to do type generation from other schemas like API contracts, GraphQL queries, etc.

@vkurchatkin
Copy link
Contributor

I've explored RPC-based plugin approach. Seems doable, but hard to predict performance implications.

@LiorCohen
Copy link

Any progress on this one? Is it on some kind of roadmap? If no one else is working on such a thing, I'd consider taking it on as a weekend project (once I've gotten some experience with OCaml).

TIA

@stereobooster
Copy link

I'm looking for contracts (or guards) based on Flow type definitions e.g. I declare a type signature in Flow, and I would be able to do runtime check if JSON response from the server is the same as my expected signature. If not it will return Nothing (from Maybe) or throw an error. This is similar to what they do in Elm. Anybody aware of something like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants