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

Generate Typescript Definitions from sanctuary-def declarations #95

Open
JAForbes opened this issue Nov 6, 2016 · 2 comments
Open

Generate Typescript Definitions from sanctuary-def declarations #95

JAForbes opened this issue Nov 6, 2016 · 2 comments

Comments

@JAForbes
Copy link
Member

JAForbes commented Nov 6, 2016

This might be impossible, but I'd be willing to explore it if anyone else is interested.

If a definition was statically analysable (no dynamic generation of types), it should technically be possible to spit out a typescript <filename>.tsd definition file that matches the runtime definitions.

You'd get compile time and run time checking in tandem for free, and editor support.

The .tsd files would automatically be detected by typescript tooling (editors/command line tools) whenever that module is required/imported.

Something like:

const add = 
  $.def('add', {}, [$.Number, $.Number], (a,b) => a + b)

Might generate:

type add = (a : number, b: number ) : number

And something like:

const a = $.TypeVariable('a')
const SomeRecord = $.RecordType({ a: $.String , b: $.Function(a) })

Might generate

interface SomeRecord {
  a: string
  , b: (a: <T>) : T
}

The tool in question could bail out if the sanctuary definitions aren't statically analyzable, and suggest ways to make it analysable (using const for example).

As I said, this may be impossible, but I thought I'd at least suggest it. :)

@davidchambers
Copy link
Member

This would be very cool indeed. It's somewhat related to #39.

@RichardForrester
Copy link

It seems that this has been done several times now, e.g., PropTypes, GraphQL.

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

3 participants