specta-rs / specta

Easily export your Rust types to other languages
MIT License
291 stars 41 forks source link

`&'a [&'a str]` become `string` instead of `string[]` #281

Closed anatawa12 closed 3 months ago

anatawa12 commented 3 months ago

I'm using 2.0.0-rc.20

I tried export the following type to typescript through tauri-specta

#[derive(Serialize, specta::Type)]
#[serde(rename_all = "camelCase")]
pub struct GlobalInfo<'a> {
    language: &'a str,
    theme: &'a str,
    version: Option<&'a str>,
    commit_hash: Option<&'a str>,
    os_type: &'a str,
    arch: &'a str,
    os_info: &'a str,
    webview_version: &'a str,
    local_app_data: &'a str,
    default_unity_arguments: &'a [&'a str],
}

but it generates type like this

export type GlobalInfo = { language: string; theme: string; version: string | null; commitHash: string | null; osType: string; arch: string; osInfo: string; webviewVersion: string; localAppData: string; defaultUnityArguments: string }

In this type, defaultUnityArguments (in rust default_unity_arguments: &'a [&'a str]) should be string[] because array of string, but specta generates string

oscartbeaumont commented 3 months ago

For some reason assert_ts!(&[&str], "string[]"); works but when the type is put in a struct it breaks so that explained how this wasn't noticed earlier.

The bug is this implementation as we passthrough to T and not Vec<T>.