Feature request: add an attribute to allow for types defined in ts only
I am retriving records from a database, and one or more of the columns is a json datatype stored in a single column. I represent this using the type JsonValue, which wraps serde_json::Value.
Right now, the following works just fine, but results in the SomeStruct type having a field with an unknown type.
pub struct SomeStruct {
#[ts(type="unknown")]
pub questionare_results: JsonValue,
}
#[repr(transparent)]
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
pub struct JsonValue(pub serde_json::Value);
export type SomeStruct = { questionare_results: unknown, };
Somthing like this would be ideal:
pub struct SomeStruct {
#[ts(type="QuestionareResults", importedFrom="../QuestionareResults.ts")]
pub questionare_results: JsonValue,
}
import type { QuestionareResults } from "../QuestionareResults.ts"
export type SomeStruct = { questionare_results: QuestionareResults, };
Perhaps a default import as well?
pub struct SomeStruct {
#[ts(defaultType="QuestionareResults", importedFrom="../QuestionareResults.ts")]
pub questionare_results: JsonValue,
}
import type QuestionareResults from "../QuestionareResults.ts"
export type SomeStruct = { questionare_results: QuestionareResults, };
Hey @legomind, this is an interesting idea! We can't use #[ts(type = "...")] for this since we use that for type overrides, but we could make a #[ts(import(type = "QuestionareResults", from = "../QuestionareResults"))] or something like that
One caveat is that I don't think our import logic handles default imports, since all our exports are named, so you might need to export QuestionareResults as a named export
The issue of external types has come up a few times. My favorite approch so far has been
#[ts(type = "import('./somewhere').SomeThing")]. While I am not against adding better support for these usecases, I havent seen anything more elegant than this.