impero-com / typebinder

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

Fix ArrayType wrong representation and array+collection solvers #31

Closed AlisCode closed 3 years ago

AlisCode commented 3 years ago

ArrayType used to allow only PrimaryType as its inner type, meaning it wasnt possible to represent types such as :

type MyType = (A|B)[];
type MyType = (A&B)[];

which are in fact valid TypeScript.

ArrayType should be either a PrimaryType or a ParenthesizedType to allow for that representation. Changing this fixes both the Array and the Collections solvers, allowing for representation of Rust types such as Vec<Option<T>>.

greyblake commented 3 years ago

Running make results into a compilation error

error[E0308]: mismatched types
   --> ts_json_subset/src/types.rs:329:28
    |
329 |             ArrayType::new(PrimaryType::Predefined(PredefinedType::Any)).to_string(),
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                            |
    |                            expected enum `types::TsType`, found enum `types::PrimaryType`
    |                            help: try using a variant of the expected enum: `types::TsType::PrimaryType(PrimaryType::Predefined(PredefinedType::Any))`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `ts_json_subset`
AlisCode commented 3 years ago

Pushed the fix for tests as well, thanks for reviewing :)