I was expecting the c# DateTimes to translate into Dates in typescript.
Any ideas?
On an aside: I’ve also found the Update ServiceStack Reference doesn’t work. It seems to alter the BaseUrl in the comments and subsequent updates fail because a types/typescript suffix is ultimately appended to the base url more than once…
The TypeScript classes represent the schema of the returned JSON which doesn’t have a Date Type, it’s defined as a string because that’s how it’s returned in JSON.
When you’re adding the reference are you using the BaseUrl?
Yeah, makes sense and tbh I should have thought of that as I am always having to handle dates separately on my son responses.
It feels to me that SS does a lot of the heavy lifting for me in generating these types but stops just short of generating typescript references. It would be nice if, in the generated typescript, a method is created to convert to/from string to Date and some further classes that represent typescript versions of the c# classes rather than json versions.
Thoughts?
Or perhaps I’m missing something? (I’m no js or ts expert tbh)
The TypeScript only generates the Type representation of the JSON Schema, it can’t do more than that because JavaScript doesn’t have any Type Information of classes at runtime. Different ways to convert Dates are listed in this StackOverflow answer: https://stackoverflow.com/a/44268376/85785
E.g. from TypeScript you can do:
import { todate } from "@servicestack/client";
var date = todate(wcfDateString);
Can you provide details of your Server, e.g. ASP.NET / .NET Core / HttpListner + the config mapping you’re using for /api in both code and Web.config please.
new AppHost(new InitialisationList(initialisers)).Init().Start("http://*:8088/");
"RESTful Web API listening at http://localhost:8088 ".Print();
Process.Start("http://localhost:8088/");
I would just need an empty project with the configuration causing the issue, can you please post the BaseUrl returned in the comments from: http://localhost:8088/api/types/typescript
The issue was due to the plugin sending an empty // double-slash in the URL. Both ASP.NET and .NET Core seem to automatically strip empty double slashes so I’ve updated HttpListener hosts to do the same which fixes this issue.
I’ve also published a fix to the Intellij Plugin to prevent the // but it takes a couple of days for JetBrains to manually verify and approve the plugin.