Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
179 stars 75 forks source link

revisit plainDate and plainTime type generation #2730

Closed qiaozha closed 2 months ago

qiaozha commented 3 months ago

As confirmed by Timothee in https://github.com/Azure/cadl-ranch/pull/641#discussion_r1700221276, the typespec plainDate is an iso format date string over the json by default and plainTime is the the iso format time string.

our current bahaviour is: TypeSpec type RLC input RLC output Modular layer
plainDate Date \| string string Date
plainTime Date \| string string Date

For plainDate, the problem is we don't have a direct way get the iso date string and we don't want to import moment.js or date-fns in our SDK, the best we could do is something like

new Date().toISOString().split("T")[0]

Which doesn't seem to be a good way to be honest.

This is also problematic for plainTime because if we get a string like "13:06:12", we have no way to build a Date type based on that.

new Date("13:06:12"); // we will get a invalid date. 

Proposal:

  1. change both plainDate and plainTime to string for both RLC and Modular. Customers can choose how to serialize a Date to string as appropriate.
  2. model as our own object as defined in the loop
joheredi commented 2 months ago

I think option 1 makes sense at this point of time. We are still some time away from Temporal being widely available and taking in an API closer to it might cause a bit of friction for most customers today. I'm happy to discuss option 2 if anyone feels strongly.

qiaozha commented 2 months ago

I also think option 1 makes sense for now. Maybe we should just go with option 1.