Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Change the representation of unit types #98

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/data/tests/boxed_value/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** This is a comment. */
export type Colors =
| { type: "Red", content?: undefined }
| { type: "Blue", content?: undefined }
| { type: "Red", content: null }
| { type: "Blue", content: null }
| { type: "Green", content: string };

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SomeEnum =
| { type: "A", content?: undefined }
| { type: "A", content: null }
| { type: "C", content: number };

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export interface AddressDetails {

export type Address =
| { type: "FixedAddress", content: AddressDetails }
| { type: "NoFixedAddress", content?: undefined };
| { type: "NoFixedAddress", content: null };

2 changes: 1 addition & 1 deletion core/data/tests/can_generate_generic_struct/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export type EnumUsingGenericStruct =
| { type: "VariantA", content: GenericStruct<string, number> }
| { type: "VariantB", content: GenericStruct<string, number> }
| { type: "VariantC", content: GenericStruct<string, boolean> }
| { type: "VariantD", content: GenericStructUsingGenericStruct<undefined> };
| { type: "VariantD", content: GenericStructUsingGenericStruct<null> };

4 changes: 2 additions & 2 deletions core/data/tests/can_handle_anonymous_struct/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export type AutofilledBy =

/** This is a comment (yareek sameek wuz here) */
export type EnumWithManyVariants =
| { type: "UnitVariant", content?: undefined }
| { type: "UnitVariant", content: null }
| { type: "TupleVariantString", content: string }
| { type: "AnonVariant", content: {
uuid: string;
}}
| { type: "TupleVariantInt", content: number }
| { type: "AnotherUnitVariant", content?: undefined }
| { type: "AnotherUnitVariant", content: null }
| { type: "AnotherAnonVariant", content: {
uuid: string;
thing: number;
Expand Down
4 changes: 2 additions & 2 deletions core/data/tests/can_handle_unit_type/output.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** This struct has a unit field */
export interface StructHasVoidType {
thisIsAUnit: undefined;
thisIsAUnit: null;
}

/** This enum has a variant associated with unit data */
export type EnumHasVoidType =
| { type: "hasAUnit", content: undefined };
| { type: "hasAUnit", content: null };

4 changes: 2 additions & 2 deletions core/src/language/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Language for TypeScript {
},
self.format_type(rtype2, generic_types)?
)),
SpecialRustType::Unit => Ok("undefined".into()),
SpecialRustType::Unit => Ok("null".into()),
SpecialRustType::String => Ok("string".into()),
SpecialRustType::I8
| SpecialRustType::U8
Expand Down Expand Up @@ -188,7 +188,7 @@ impl TypeScript {
match v {
RustEnumVariant::Unit(shared) => write!(
w,
"\t| {{ {}: {:?}, {}?: undefined }}",
"\t| {{ {}: {:?}, {}: null }}",
tag_key, shared.id.renamed, content_key
),
RustEnumVariant::Tuple { ty, shared } => {
Expand Down