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

[WIP] Attempted conversion of i18n package #12201

Closed
wants to merge 1 commit into from
Closed

Conversation

barklund
Copy link
Contributor

Context

This is a first attempt at converting the i18n package to TypeScript.

Testing Instructions

  • This is a non-user-facing change and requires no QA

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This code is covered by automated tests (unit, integration, and/or e2e) to verify it works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #

@barklund barklund added Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️ Pod: Prometheus labels Aug 31, 2022
@barklund barklund self-assigned this Aug 31, 2022
Comment on lines -61 to -63
const children = node.hasChildNodes()
? [...childNodes].map((child) => transform(child, mapping))
: null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am pretty sure this old code is wrong, no? It loops over all the child nodes and transforms each, but transformNode transform both the given node and all its following siblings, so this old code duplicates a lot of nodes, no?

Well, at least the type system told me that the children variable had type ReactNode[][], which definitely seemed wrong.

if ('localName' in node) {
const { localName } = node as Element;
if (localName in mapping) {
return cloneElement(mapping[localName], undefined, children);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the life of me, I can't figure out how to get TS to accept the type of this one? I tried everything, but I can't match the types to any of the overloads available. And similarly for createElement and its overloads a few lines below.

@swissspidy
Copy link
Collaborator

@barklund Did you miss #12198?

@barklund
Copy link
Contributor Author

barklund commented Sep 1, 2022

@barklund Did you miss #12198?

Obviously! Sorry about that - I did try to search for it, but clearly weren't that good at it. 🤦

Luckily I didn't spend too much time on this, and maybe some of the work can be reused? I'll check your PR later and close this one.

@swissspidy
Copy link
Collaborator

Merged #12198 now. Feel free to rebase your PR if you have any suggestions for improvements!

@barklund barklund closed this Sep 5, 2022
@swissspidy swissspidy deleted the code/ts-i18n branch September 5, 2022 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Code Quality Things that need a refactor, rewrite or just some good old developer ❤️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants