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

[rust] Refine typescript type generation #3239

Conversation

MaartenStaa
Copy link
Contributor

Fixes #3196

The generated output should now be basically identical to what is being generated over at relay-tools/relay-compiler-language-typescript. I didn't write a script to compare the fixtures in an automated manner, but compared samples by hand and fixed cases where the output from the Rust compiler differed.

Looking forward to your feedback!

@MaartenStaa
Copy link
Contributor Author

Just realized I should probably ping @kassens @maraisr and @alloy at least.

readonly " $fragmentRefs": FragmentRefs<"PictureFragment">,
} | null,
readonly " $fragmentRefs": FragmentRefs<"OtherFragment" | "UserFrag1" | "UserFrag2">,
readonly " $refType": FragmentRefs<"FragmentSpread">,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kassens Just a FYI: If you were to switch the Flow emission to use types like these (based on strings) as well, instead of opaque types, we could get rid of any additional code related to haste or a specific artifact directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. This is using the fragment names and the fact that they're globally unique as their identifier, clever!

What about the property names? Why " $refType" as the key (leading space?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I wasn't involved with the original design behind the Typescript types, but I believe the leading space causes Typescript to omit this property in its autocomplete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I wasn't involved with the original design behind the Typescript types, but I believe the leading space causes Typescript to omit this property in its autocomplete.

Correct 👍

Copy link
Contributor

@alloy alloy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reviewed the emitted TS and it looks stellar to me 👌 Thanks! 🙏

@kassens
Copy link
Member

kassens commented Nov 17, 2020

Sorry for missing this!

Curious about the import type, that's a new TypeScript feature, so it's there to support versions before and after TS 3.8?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kassens has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@MaartenStaa
Copy link
Contributor Author

Sorry for missing this!

Curious about the import type, that's a new TypeScript feature, so it's there to support versions before and after TS 3.8?

No problem! Yeah, the import type syntax was introduced in TypeScript 3.8. So in older versions you'd just use the regular ES import x from y syntax to import both values and types. This still works in in later versions as well, but import type is semantically more clear. Also, some lint rules would complain about unused values if you don't use import type, though I have personally not run into this problem.

@kassens
Copy link
Member

kassens commented Nov 30, 2020

Sorry for the delay, I was on vacation last week, but this should be merged in a bit!

@kassens
Copy link
Member

kassens commented Nov 30, 2020

Thanks for the contribution again! Helps us slowly to get OSS ready!

@facebook-github-bot
Copy link
Contributor

@kassens merged this pull request in aab3622.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[rust] refine typescript type generation
4 participants