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

Improve type error messages and tooltips #910

Merged
merged 12 commits into from
May 28, 2020

Conversation

hasparus
Copy link
Member

@hasparus hasparus commented May 10, 2020

Okay this might be a small thing, but I want to add some polish (lol) to the types.

Generally, the problem we have is that our types, mostly imported from DT, may be a bit confusing.
I'd like to make Theme UI types as welcoming as possible for v1 (#832)

Related issues:

  • Usage of Theme UI with TypeScript #834 (comment)
    • Add TypeScript section to the docs to explain most common tricky things people can see
  • Usage of Theme UI with TypeScript #834 (comment)
    • Move all tests to TypeScript. We can't be sure Theme UI works in TypeScript if we don't typecheck our tests.
    • Get rid of generic parameter for merge. Use Theme as argument.
  • Use const inside sx #907
    • Get inspired by Emotion's Interpolation and display errors on SystemStyleObject better.
  • We don't support vendor properties. Why? They are defined in csstype and we actually have them inside StandardCSSProperties, but they don't come to sx prop. I can't see a reason we shouldn't support vendor properties on type level, while they work at runtime.
    • Let's add CSS.VendorProperties<number | string> to CSSProperties type.
  • Add label?: string to ThemeUIStyleObject ([@types/theme-ui] SxStyleProp & Emotion's label DefinitelyTyped/DefinitelyTyped#45020 (comment))
  • Rename SystemStyleObject to ThemeUIStyleObject.
    • System is a loaded word in our industry, and the name is inherited from styled-system. It might be more user-friendly to tidy up few types and use a mix of nice meaningful names and dumb straightforwad names.

Few notes to explain what I'm doing.

@hasparus hasparus marked this pull request as draft May 10, 2020 18:42
hasparus added 2 commits May 24, 2020 11:25
- Interfaces support declaration merging, and thus are superior in this
  case. An user can add his own color names. The index signature might
  be removed some day for "strict mode".

- The comment is outdated.

- Smaller types in tooltips lead to more readable type errors.
@hasparus
Copy link
Member Author

hasparus commented May 24, 2020

@jxnblk Which colors in theme.colors should be required? ATM in TS types, it's background and text. Based on the tests, I'd assume none are required, but having a few may be good for interoperability.

I'm making them all optional for now to avoid changing so many tests.

@hasparus hasparus force-pushed the simplify-types branch 2 times, most recently from 94b7162 to 2bef788 Compare May 24, 2020 14:10
@hasparus hasparus requested review from jxnblk and mxstbr May 24, 2020 14:41
@hasparus hasparus marked this pull request as ready for review May 24, 2020 14:41
@hasparus hasparus changed the title WIP: Improve type error messages and tooltips Improve type error messages and tooltips May 24, 2020
@@ -373,14 +372,14 @@ test('warns when initialColorModeName matches a key in theme.colors.modes', () =
})

test('dot notation works with color modes', () => {
const Button = (props) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

damn, can't Prettier decide on one style? I'll revert this change.

@hasparus
Copy link
Member Author

This is starting to become pretty big, and while I didn't tackle all todos yet, it might be good to start reviewing before it becomes overwhelming.

Copy link
Member

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

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

I love this cleanup!! 🔥 So good 👍

Do you want to ship this as-is and work on the other fixes in another PR or keep this one around for a bit longer?

@jxnblk
Copy link
Member

jxnblk commented May 26, 2020

Which colors in theme.colors should be required?

Generally speaking, none should be required, but the color mode functionality does depend on the colors.text and colors.background keys being defined.

For the interoperability part, I think we'll want to create a "blessed" Theme interface (along with some color palette interfaces) after the TS conversion is out as an optional piece of the puzzle, but not sure if that's helpful here

Copy link
Member

@jxnblk jxnblk left a comment

Choose a reason for hiding this comment

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

Looks generally good to me -- I'd say feel free to merge this whenever and continue to iterate with more PRs, if that makes working on this easier

@@ -1,11 +1,11 @@
import { SystemStyleObject } from '@theme-ui/css'
import { ThemeUIStyleObject } from '@theme-ui/css'
Copy link
Member

Choose a reason for hiding this comment

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

Not to bikeshed, but this is a much better name :)

@hasparus hasparus merged commit 2c72fa1 into system-ui:master May 28, 2020
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.

3 participants