-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
TypeScript migration of @emotion/utils #2359
TypeScript migration of @emotion/utils #2359
Conversation
🦋 Changeset detectedLatest commit: 3c57837 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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 1a93635:
|
Thank you for starting this! I've already played a little bit with your branch locally and trying to wrestle the config-related stuff. It might take me some days - since I have to pause working on this and won't be available much in the following days but I will get back to this ASAP and get this through the finish line! |
packages/utils/src/types.ts
Outdated
|
||
export type EmotionCache = { | ||
inserted: { [string]: string | true }, | ||
inserted: Record<string, string | boolean>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be more consistent to keep the type literal true
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a casual consumer of this repo, I love seeing this work starting! Left a comment and gonna see what I can do to contribute here, too 🙇
@@ -44,7 +43,7 @@ export const insertStyles = ( | |||
} | |||
if (cache.inserted[serialized.name] === undefined) { | |||
let stylesForSSR = '' | |||
let current = serialized | |||
let current: SerializedStyles | undefined = serialized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even actually possible for serialized
to be undefined
here? I would've expected if (cache.inserted[serialized.name] === undefined) {
to error from accessing undefined.name
if so.
If that's actually possible, would it make sense to introduce optional chaining into the if statement's syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is current
-specific typing in advance because current.next
is possibly undefined and we're checking against it as part of the do
/while
:
emotion/packages/utils/src/index.ts
Lines 46 to 58 in 3f66787
let current: SerializedStyles | undefined = serialized | |
do { | |
let maybeStyles = cache.insert( | |
serialized === current ? `.${className}` : '', | |
current, | |
cache.sheet, | |
true | |
) | |
if (!isBrowser && maybeStyles !== undefined) { | |
stylesForSSR += maybeStyles | |
} | |
current = current.next | |
} while (current !== undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, gotcha, that makes sense. I haven't seen a while loop like this in a while :pun-dog: so it threw me. Thanks for the quick update!
@rjdestigter ive merged in TS tooling setup into |
# Conflicts: # .eslintignore # packages/utils/src/index.ts # packages/utils/src/types.ts # packages/utils/tsconfig.json
What:
Migrating @emotion/utils from Javascript + Flow to TypeScript.
This was an initial stab at migrating a package to TypeScript. I'm primarily running into problems with linting. I had to add a line to .eslintignore due to ESLint not understanding optional properties on types and interfaces. This first commit also used
--no-verify
as the commit hook script also failed for similar reasons.I kept the old declaration for now to use in the
test.ts
file to make sure that the auto generated function signatures matched the older declaration.Build and tests do succeed on this branch atm.
Todo:
Why:
#2358
How:
*.js
files to*.ts
and removed references to FlowChecklist:
More todos: