typescript-generator-core: How can I, given a Type, get its TypeScript name?
crummy opened this issue · 2 comments
crummy commented
I use typescript-generator to generate types for all our shared backend/frontend classes (and I love it - thank you!)
I'm building an TypeScript API generator for our backend but can't figure out how to get the name of a class given a type. For example:
interface Sample {
void foo(int i);
}
for (Method m in Sample.class.getMethods()) {
for (Type javaType : primitives.getGenericParameterTypes()) {
String typeScriptType = ??? // should return "Number"
}
}
I tried this, but it generates entire interfaces:
new TypeScriptGenerator(settings).generateTypeScript(Input.from(type));
markhuang19994 commented
Although it's a bit late, I hope my code can help you.
val settings = new Settings();
val tsType = new TypeScriptGenerator(settings)
.processTypeInTemporaryContext(Long.class, null, settings)
.getTsType();
or
val settings = new Settings();
val tsType = new TypeScriptGenerator(settings)
.getModelCompiler()
.javaToTypeScript(Long.class)
.format(settings);
crummy commented
Thanks, that's just what I was looking for!