-
Notifications
You must be signed in to change notification settings - Fork 673
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
Adopt TS in theme-ui/color #672
Conversation
packages/color/package.json
Outdated
@@ -11,6 +13,9 @@ | |||
"@theme-ui/css": "^0.3.1", | |||
"polished": "^3.4.1" | |||
}, | |||
"peerDependencies": { |
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 we should come to a consensus here whether to put the dependencies for types in peerDep, devDep or Dep. I opted for devDep: https://github.com/system-ui/theme-ui/pull/671/files#diff-03713682702149e044f8824251410926R22
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.
yeah, previously the packages depended on common concepts.
These concepts are now described as types and we keep them in @theme-ui/core
, so the dependency needs to be noted in package.json.
I think there are two possibilities:
@theme-ui/color
has@theme-ui/core
both in peer dependencies and a dev dependencies.- Dev dep only would be a TypeScript build error for users without any previous warning. This is also how I got "semantic error TS2307 Cannot find module '@theme-ui/core'." on Circle CI :D
@theme-ui/color
depends on@theme-ui/core
. It should be okay in monorepo with the same versions. I think I'll go this way sincecolor
already depends oncss
.
After the build there is no import to @theme-ui/core
so it won't get bundled for people who use only color utils.
I've added ts-jest, mostly because I didn't notice it's not here before changing
|
Thanks for diving into this! Just a couple quick thoughts:
Yes, we want to have better checks for typos from keys you've defined in your theme interface. Not sure what that ultimately will look like, but I'm guessing it's okay to punt on this for now with
All |
Sure, I just wanted to drop some notes.
So The dependency on core here could be dropped when @theme-ui/css exports |
@hasparus let's use ts-node for all the tests! 💯 |
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.
This looks great, thanks for also converting the tests that makes a lot of sense! 🔥
Do you want to move the Theme
to css
in this PR too so we avoid all weirdness entirely? I think that makes a lot of sense.
Moving Theme turned out to be a pretty big change. This PR consumed #673. |
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.
One comment and one request. Looks good!
"esModuleInterop": true, | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"] |
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.
Did you run into issues without that explicit include
?
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.
Yup, tests get built.
dist
src
test
index.test.d.ts
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.
Makes sense! Might want to add that to other files in a follow-up PR then
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.
Since this is a monorepo, we could add tsconfig.json
to the root with all base compiler options (like moduleResolution node
and no resolveJsonModule
) and then use "extends"
to inherit them. The tsconfig in root would be useful when you open the entire repo in an IDE.
I'm not sure for 100%, but I think "include" is inherited literally (relative to the new config, not to the parent), so most tsconfigs in packages could look like
{
"extends": "../core/tsconfig.json",
"compilerOptions": {
"strict": true // if possible since core is unstrict
}
}
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.
Yes we should totally do this! 👍
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.
Amazing! 🔥 Thank you for tackling this!
Part of #668
I noticed @LekoArts is doing conventional commits and I'm stealing the idea.
Changes
Adopted TypeScript
I commited this in a weird way to preserve file history (two first commits on this branch).
Added jsdoc comments
I've added jsdocs with descriptions from README,
because they're visible in tooltips when you hover a function.
(accessible by ts.getLeadingCommentRanges in Compiler API)
Added grayscale to README
This is a separate commit, so we can revert it easily.
I noticed it's missing and it doesn't look like it's internal API,
so I took to add it.
Possible further work
TSDoc comments parameter descriptions
Autocomplete color names dependent on theme type?s correctly.
My colleague has mentioned the fact that we get editor support for
color names in
sx
prop and functions from@theme-ui/color
during development as a biggest DX limitation of theme-ui.
We can write a typo (like "primry") and it still typechecks
It could be implemented by removing string index signature
from ColorMode and turning ColorMode into an interface so more
properties can be added with declaration merging
and module augmentation.
After such action, instead of
string
color parameters in theme-ui/color wouldbe typed as
ColorName
(or something similar).I am not sure if it is legal to pass color representation (e.g. "#fff")
to the functions here. I'm looking at
g
function and I think it isn't, it isalso undocumented, so I'll assume that it's not.