-
Notifications
You must be signed in to change notification settings - Fork 5
Description
I have an "ID" type that is serialized in a non-standard way. It is a data class that looks like this:
@ExportTypescriptType
@Serializable(with = ...)
data class FooId(override val value: Int)
and the custom kotlinx serializer serializes it to a prefixed literal value e.g. FooId(222) is serialized to foo_222.
Now of course if I have a type like this:
@ExportTypescriptType
data class Foo(
val id: FooId,
)
reakt-native-toolkit generates Typescript that looks like this:
export interface Foo {
id: FooId;
}
export interface FooId {
value: number;
}
which of course does not represent the JSON correctly. which looks like this:
{
"id": "foo_222",
}I'd like to be able to control the type of the Typescript field via annotation e.g.:
@ExportTypescriptType
data class Foo(
val id: @JsType("string") FooId,
)
in other words, I'm telling reakt-native-toolkit the type of the id field so that it does not have to infer it.
Currently this only works for date/time fields, but I don't see why we shouldn't open it up for wider use?
Alternatively, other recommended approaches for this situation are welcome. My other workarounds are to 1) create another class that uses String for that field and then convert before sending it over the React Native interface, or 2) post-process the generated Typescript and modify it.