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

[serialize]: Convert to Typescript #2543

Merged
merged 13 commits into from
Apr 19, 2022

Conversation

danilofuchs
Copy link
Contributor

@danilofuchs danilofuchs commented Nov 9, 2021

What:

Migrates the serialize package to Typescript. This was not that simple as the internal functions deal with a large variety of possible types for each argument (Interpolation), and some were undocumented.

Why:

Part of #2358

How:

  • Convert Flow type annotations
  • Copy .d.ts definitions to main file
  • Fix whatever breaks

Checklist:

  • Documentation
  • Tests
  • Code complete
  • Changeset

@changeset-bot
Copy link

changeset-bot bot commented Nov 9, 2021

🦋 Changeset detected

Latest commit: 62719e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@emotion/serialize Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@danilofuchs
Copy link
Contributor Author

Note: This isn't finished just yet, some tests are still breaking and it's missing the changeset

Comment on lines +286 to +294
`\`keyframes\` output got interpolated into plain string, please wrap it with \`css\`.

Instead of doing this:

${[...matched, `\`${replaced}\``].join('\n')}

You should wrap it with \`css\` like this:

css\`${replaced}\``
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 rewrote this string interpolation as semantic coloring broke on VSCode due to the complex ' and ` usage
Screen Shot 2021-11-08 at 17 10 03

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 9, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 62719e2:

Sandbox Source
Emotion Configuration

@danilofuchs
Copy link
Contributor Author

Hi @Andarist, I've updated the PR with the requested changes. I made sure no runtime code changes were made.

However, some tests are now breaking. Apparently Interpolation could also be a Symbol. When adding it to the interoplated string, if throws a TypeError. Specifically, Symbol(react.forward_ref).

Perhaps something in the old Flow build output is now different, causing this unexpected bug. Either way, the code seems to not expect a Symbol value at all, and will break if called with it.

Should we apply a patch on the main branch before migrating to TS?

@@ -370,6 +453,7 @@ export const serializeStyles = function (
styles,
map: sourceMap,
next: cursor,
// @ts-ignore: SerializedStyles does not have toString method, and we don't want to add it
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 used the same comment from the original Flow code

@danilofuchs danilofuchs marked this pull request as ready for review November 16, 2021 14:59
@codecov
Copy link

codecov bot commented Nov 19, 2021

Codecov Report

Merging #2543 (62719e2) into ts-migration (17fee4b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
packages/serialize/src/index.ts 100.00% <100.00%> (ø)

@Andarist
Copy link
Member

@danilofuchs the code looks OK (i've pushed some additional, minor, changes but they were mostly nits) but some type tests are failing. I've looked briefly into failing tests for @emotion/serialize and I'm pretty sure that this is caused by older TS versions being tripped on import/export type syntax.

The problem is that we need this syntax because we compile stuff with isolatedModules. I've tried changing the minimal TS version header for this package but it turns out that we are using very old version of dtslint and it only supports up to TS 3.4 and that syntax has been introduced in 3.8 🙈

I recall that I've tried to upgrade dtslint like a year ago or something and I've bumped into some problems, didn't have enough time to dig into this back then but I guess I might have to do that after all.

@Andarist Andarist mentioned this pull request Nov 19, 2021
@Andarist Andarist merged commit 9ca22c6 into emotion-js:ts-migration Apr 19, 2022
@github-actions github-actions bot mentioned this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants