Typescript Support

196 views
Skip to first unread message

Sam Paioletti

unread,
Oct 19, 2016, 1:20:26 PM10/19/16
to FlatBuffers
Quick q for any JS/TS users out there (and Wouter). We have been using the js library for a while and would like to do some work getting it to work with typescript... a couple of paths that could be taken...

For flatbuffers.js
  1. write a typescript definition file
  2. rewrite to a proper typescript file and use ts compiler to generate js (easier to maintain)

for flatc *_generated.js
  1. Add code to generate definition file along with js file
  2. Add code to generate separately a ts file (like flatc -t , would be a lot of duplication )
  3. Rewrite code to generate only ts files and either
    1. allow users to compile their own js using tsc compiler
    2. integrate tsc compiler into flatc (we actually did this on another project using duktape.org it wasn't as difficult as it sounds)
Getting ts going for fb would be a huge win for using it in a js environment, having some type checking makes using fb so much easier.

Just wanted to see if anyone or Wouter had any thoughts on how they would like this to move forward that way we can be working in the direction the community prefers (no guarantees how long it would take for a PR, its not a top priority at the moment).

Best,

Sam

Wouter van Oortmerssen

unread,
Oct 19, 2016, 1:34:49 PM10/19/16
to Sam Paioletti, FlatBuffers
My quick thoughts are that a) supporting TS would be cool (especially since FB is typed, so a good fit!), but b) that we can't require regular JS users (or even people contributing to the JS implementation) to have to use TS to do their work.

As such, starting out with a definition file seems a good first step. For generating code, I don't think it would be too hard to modify the code generator such that it can output both JS and TS (e.g. optionally appending ": type" to arguments etc.)

Integrating the TS compiler into flatc is a no-go, we'd like to keep the FlatBuffers project free of dependencies and lightweight.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sam Paioletti

unread,
Oct 19, 2016, 2:50:28 PM10/19/16
to FlatBuffers
Ok thanks for the quick thoughts...

the only point i'll disagree with (respectfully) is the actual flatbuffers.js file, only speaking from experience... 
  1. libraries written in ts are much easier to maintain and test
  2. could just require that any PR include updated js
  3. contributors can submit vanilla js since it compiles without issue, and then somebody else can ts it in another PR
  4. much more work to maintain a separate typefile
Just want to put in my 2c but could always reevaluate later if the ts becomes popular

I think your probably right on leveraging the existing compiler code and just appending type arguments..hadn't thought of it that way.

Won't argue (too much, haha) if thats what you want we'll go with your judgement.

I'll work on a PR with a d.ts file and look into the flatc compiler side in my spare time.


Thanks again.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.

Wouter van Oortmerssen

unread,
Oct 19, 2016, 4:22:36 PM10/19/16
to Sam Paioletti, FlatBuffers
Hey, I prefer typed languages myself. But I have to make sure the project is very easy to work with by the majority of JS users. We can revisit that as things progress :)

To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.

Sam Paioletti

unread,
Oct 19, 2016, 4:24:20 PM10/19/16
to Wouter van Oortmerssen, FlatBuffers

Sounds like a plan

Sam Paioletti

unread,
Oct 19, 2016, 4:40:13 PM10/19/16
to Wouter van Oortmerssen, FlatBuffers

Would you prefer it integrated as another generator or as an option

 

i.e.

flatc --js myIdl.fbs –gen-ts (generates both js and ts or only ts?)

or

flatc --ts myIdl.fbs (generates only ts)

 

From: Wouter van Oortmerssen [mailto:w...@google.com]
Sent: Wednesday, October 19, 2016 2:23 PM
To: Sam Paioletti <sampai...@gmail.com>
Cc: FlatBuffers <flatb...@googlegroups.com>
Subject: Re: Typescript Support

 

Hey, I prefer typed languages myself. But I have to make sure the project is very easy to work with by the majority of JS users. We can revisit that as things progress :)

Wouter van Oortmerssen

unread,
Oct 19, 2016, 4:43:42 PM10/19/16
to Sam Paioletti, FlatBuffers
The latter option makes more sense to me. They both would call the same js generator, but you'd set a boolean in IDLOptions that you want the output to be typed.

To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.

Sam Paioletti

unread,
Oct 19, 2016, 4:53:47 PM10/19/16
to Wouter van Oortmerssen, FlatBuffers

Sounds good thanks

Sam Paioletti

unread,
Oct 21, 2016, 1:12:21 PM10/21/16
to FlatBuffers
Working version posted to PR https://github.com/google/flatbuffers/pull/4065 . Currently passing the tests/JavsScriptTest.js suite.

Having some issues with Travis liking the ts files ...I'll need some help with how I need to commit those so it works.

peterga...@gmail.com

unread,
Feb 2, 2017, 4:11:52 AM2/2/17
to FlatBuffers
Really looking forward to this.
Reply all
Reply to author
Forward
0 new messages