impero-com / typebinder

Exports TS definitions from Rust module
Other
20 stars 2 forks source link

Add `extend string` to generic types used in object key position #25

Closed gobanos closed 3 years ago

gobanos commented 3 years ago

The following Rust struct

#[derive(Serialize, Deserialize)]
pub struct Foo<Key, Value>
where
    Key: Eq + Ord,
{
    pub foos: BTreeMap<Key, Value>,
}

is translated to this invalid typescript :

export interface Foo<Key, Value> {
    foos: Record<Key, Value> // <- Type 'Key' does not satisfy the constraint 'string | number | symbol'.
}

The expected typescript is :

export interface Foo<Key extends string, Value> {
    foos: Record<Key, Value>
}
AlisCode commented 3 years ago

So :