Skip to content

Feature request: allow method of including [propName: string]: any to type #335

@drac-dot-gay

Description

@drac-dot-gay

i have a struct with a generic i'm exporting as a typescript type, however due to this struct being a part of a library where the generic will be provided by the user, there's not really a good way to define a type. since it's flattened, what i'd want to do is include a [propName: string]: any to the end like the typescript docs recommend, but i don't see a clean way to do that. here's the closest i've been able to get:

#[derive(TS)]
pub struct AnyMarker {
    #[ts(type = "any")]
    foo: ()
}

impl Document for AnyMarker {
    fn identifier() -> &'static str {
        todo!()
    }

    fn title() -> &'static str {
        todo!()
    }

    fn fields() -> Vec<EditorField> {
        todo!()
    }

    fn validators(model: DataModel) -> HashMap<String, ValidatorFunction> {
        todo!()
    }
}

#[derive(Serialize, Deserialize, TS)]
#[ts(export)]
#[ts(concrete(D = AnyMarker))]
pub struct Item<D: Document> {
    #[serde(rename = "__sc_id")]
    pub id: String,
    #[serde(rename = "__sc_created_at")]
    pub created_at: DateTime<Utc>,
    #[serde(rename = "__sc_modified_at")]
    pub modified_at: DateTime<Utc>,
    #[serde(rename = "__sc_published_at")]
    pub published_at: Option<DateTime<Utc>>,
    #[serde(flatten)]
    pub inner: D,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions