Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

fix(css-properties): remove incorrect React.ReactChild from Lossy Union #372

Conversation

luke-john
Copy link
Collaborator

@luke-john luke-john commented Jan 8, 2018

What:

Remove React.ReactChild from css properties Lossy Unions

This was originally added to fix a problem where built in glamorous components had been typed to accept the css properties union which included the lossy version.

By updating that component to instead use the css CompleteSingle interface the React.ReactChild is able to be removed.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged

@codecov-io
Copy link

codecov-io commented Jan 8, 2018

Codecov Report

Merging #372 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #372   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         182    182           
  Branches       52     52           
=====================================
  Hits          182    182

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b843c27...8738c76. Read the comment docs.

@luke-john luke-john force-pushed the fix/built-in-glamorous-components_properties branch from 7b5ad84 to 7912617 Compare January 8, 2018 02:38
@denis-sokolov
Copy link

This clearly looks like a better solution. However, with TypeScript 2.6.1 your PR fails to typecheck my codebase.

<Div height={18}>
  <MyComponent />
</Div>
error TS2322: Type '{ height: 18; children: Element; }' is not assignable to type 'IntrinsicAttributes & CSSProperties & ExtraGlamorousProps & HTMLProps<HTMLDivElement> & { childre...'.
  Type '{ height: 18; children: Element; }' is not assignable to type 'CSSProperties'.
    Property 'children' is incompatible with index signature.
      Type 'Element' is not assignable to type 'string | number | SingleOrArray<CSSPropertiesCompleteSingle, "alignContent" | "alignItems" | "ali...'.
        Type 'Element' is not assignable to type '(string | number | {} | ("inherit" | "initial" | "unset" | "flex-start" | "flex-end" | "center" |...'.

I don’t understand why, since the test cases clearly include this. :-(

@luke-john luke-john force-pushed the fix/built-in-glamorous-components_properties branch from a10f44d to 4a1598c Compare January 8, 2018 08:05
@luke-john
Copy link
Collaborator Author

🤔 Are you able to share a version of MyComponent that is failing? I'm unable reproduce the issue locally (using 2.6.1 and 2.6.2).

I've added additional cases to test component signatures being accepted as children to this pr. https://github.com/luke-john/glamorous/blob/4a1598ca1a97d72c02ab54ecaccea3a1b9d8133c/test/glamorous.test.tsx#L568-L585

@luke-john
Copy link
Collaborator Author

actually are you sure you're using this version? I'm a little bit suspicious of that error containing CSSProperties.

error TS2322: Type '{ height: 18; children: Element; }' is not assignable to type 'IntrinsicAttributes & CSSProperties & ExtraGlamorousProps & HTMLProps<HTMLDivElement> & { childre...'.

@denis-sokolov
Copy link

Hm, strange. I will test more thoroughly in the next day or two.

@Ailrun
Copy link
Contributor

Ailrun commented Jan 8, 2018

@luke-john, @denis-sokolov is right.
Since by

{
  [propertyName: string]: T
}

T is intersected with every properties including children, T should include the types for children or ref, onClick ...

@@ -1926,7 +1926,6 @@ export interface CSSPropertiesLossy {
| undefined
| Array<CSSPropertiesComplete[keyof CSSPropertiesComplete]>
| CSSPropertiesLossy
| React.ReactChild
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause the same problem of #353

Copy link
Contributor

@Ailrun Ailrun Jan 8, 2018

Choose a reason for hiding this comment

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

This is the minimal PoC for common problem.
https://goo.gl/kjc8XD

Copy link
Contributor

@Ailrun Ailrun Jan 8, 2018

Choose a reason for hiding this comment

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

IMO, to remove this extra union (as we want), we need to solve #353 first.

@luke-john
Copy link
Collaborator Author

luke-john commented Jan 9, 2018

Ahh right, cheers for that @Ailrun, I've recently left my last workplace so don't have any large codebases to test prs on at the moment.

Something is clearly going wrong here as the type for glamorous.Div is not matching the type for the named export Div.

screen shot 2018-01-09 at 11 10 23 am

screen shot 2018-01-09 at 11 09 55 am

@luke-john
Copy link
Collaborator Author

🤦‍♂️ Ahh I forgot to read the important comment at the top of that file

// The file `./named-built-in-glamorous-components.d.ts` is based off this file
// and should get any updates this file does.

will update shortly. thanks

>
Wbr: React.StatelessComponent<
CSSProperties & ExtraGlamorousProps & React.HTMLProps<HTMLElement>
CSSPropertiesCompleteSingle &
Copy link
Contributor

@Ailrun Ailrun Jan 9, 2018

Choose a reason for hiding this comment

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

So being unable to use ':active' or other pseudo properties works as intended?
I mean,

const props = {
  ':active': {
    color: 'purple'
  }
};

<glamorous.A {...props} />

Is invalid?
I beg your understanding for my ignorance of whole project structure itself. (I just skim whole codes after I became a collaborator, because of lack of time...)

Copy link
Collaborator Author

@luke-john luke-john Jan 9, 2018

Choose a reason for hiding this comment

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

hmm, I hadn't really thought about spreading the css props on.

🤔 That is valid, but as I understood it the purpose of that api was to make it possible to simple add css properties like follows;

<glamorous.A color="purple" />

And for the pattern you're describing do something like follows

const cssProps = {
  ':active': {
    color: 'purple'
  }
};
<glamorous.A css={props} />

I'm leaning towards making the types simpler here to reflect the intended use. As otherwise it makes the types less useful elsewhere.

Really appreciate your feedback and taking the time to go over these prs and even skimming the code 💖.

Copy link
Collaborator Author

@luke-john luke-john Jan 9, 2018

Choose a reason for hiding this comment

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

We could add CSSPropertiesPseudo to the Intersection which would allow the case you've raised to work. But it would still fall down on things like

const props = {
  '> span': {
    color: 'purple'
  }
};

<glamorous.A {...props}>hello <span>world</span></glamorous.A>

Copy link
Contributor

@Ailrun Ailrun Jan 9, 2018

Choose a reason for hiding this comment

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

Thank you for your kind answer!
I think I fully get the point what you want to say, and I agree with it to some distance. I will approve this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added test cases for the pseudo props as part of this pr as well, cheers.

https://github.com/luke-john/glamorous/blob/a821469f2cad3c8511bbdfc12d2c807d6cc4d08f/test/glamorous.test.tsx#L611-L621

Ailrun
Ailrun previously approved these changes Jan 9, 2018
This was originally added to fix a problem where built in glamorous components had been typed to accept the css properties union which included the lossy version.

By updating that component to instead use the css CompleteSingle interface the React.ReactChild is able to be removed.
@luke-john luke-john force-pushed the fix/built-in-glamorous-components_properties branch from 5716958 to a821469 Compare January 9, 2018 06:32
@Ailrun
Copy link
Contributor

Ailrun commented Jan 10, 2018

@luke-john Following is just a question. If you give me an answer, I would greatly appreciate it.

Is there any reason for dismissing the review?

@denis-sokolov
Copy link

My speculation would be Luke wanted to express a need for you to review it afresh after the latest changes, @Ailrun.

I promised to test this again until today, @luke-john, but my schedule can’t allow it, apologies. I won’t be able to reproduce it until the weekend.

@luke-john
Copy link
Collaborator Author

@Ailrun I pushed the CSSPropertiesPseudo and test case additions for #372 (comment) after your review.

And GitHub automatically dismisses reviews when changes are made to a pull request.

@Ailrun
Copy link
Contributor

Ailrun commented Jan 10, 2018

@luke-john Thank you for explanation! I didn't know there's a case that github automatically dismisses a review.
Anyway, from my point of view, the PR looks OK.

Ailrun
Ailrun previously approved these changes Jan 10, 2018
@Ailrun
Copy link
Contributor

Ailrun commented Jan 10, 2018

And also thank you for @denis-sokolov to try to explain what I ask! I really appreciate you all!

@denis-sokolov
Copy link

GitHub does not always automatically dismiss a review, it’s a per-repository setting. Some people want to make sure that the reviewers have seen the absolutely latest version of the PR, and some are okay with relying on a more lax rule of common sense.

@denis-sokolov
Copy link

I’m confused by my tests. Minimal case that triggers the error with this branch as the dependency is this:

<Div>
  <Div />
</Div>

Obviously it is supposed to be covered in tests, but I was pretty thorough with the tests. Building glamorous at 8a0216f makes my tsc succeed, then I switch glamorous to 7912617, and tsc starts loudly failing.

This happens with tsc 2.6.1 and 2.6.2, confirmed the flow with both.

Here is the error:

index.tsx(90,7): error TS2322: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & CSSProperties & ExtraGlamorousProps & HTMLProps<HTMLDivElement> & { childre...'.
  Type '{ children: Element; }' is not assignable to type 'CSSProperties'.
    Property 'children' is incompatible with index signature.
      Type 'Element' is not assignable to type 'string | number | SingleOrArray<CSSPropertiesCompleteSingle, "alignContent" | "alignItems" | "ali...'.
        Type 'Element' is not assignable to type '(string | number | {} | ("inherit" | "initial" | "unset" | "flex-start" | "flex-end" | "center" |...'.```

@GirlBossRush
Copy link

@Ailrun,

This looks awesome! Is there an ETA to release?

@Ailrun
Copy link
Contributor

Ailrun commented Feb 11, 2018

@TeffenEllis Sorry for late response. @kentcdodds could you answer to @TeffenEllis ?

@kentcdodds
Copy link
Contributor

The releases for this project are automatic. So it should be released as soon as this is merged.

@Ailrun
Copy link
Contributor

Ailrun commented Feb 11, 2018

@kentcdodds Oh, I mean... when will this merged?

@kentcdodds
Copy link
Contributor

I keep out of typescript related stuff unless specifically asked. Do you all my help here?

Feel free to merge typescript pull requests yourself. Just make sure to follow the commit message convention when doing squash and merge so the right version is released.

@Ailrun
Copy link
Contributor

Ailrun commented Feb 11, 2018

@kentcdodds I got
image this message so I thought I can't merge this.
Am I wrong? Can I merge this?
If that's the case, I will merge this (and after, other TS related PRs).

@Ailrun Ailrun force-pushed the fix/built-in-glamorous-components_properties branch from cdc9dbc to a821469 Compare February 11, 2018 19:05
@kentcdodds
Copy link
Contributor

It's because the PR was not updated with master, so I just clicked the "Update branch" button and once the status checks are done you should be able to merge it.

Just make sure to follow the commit message conventions when you squash and merge, otherwise a new version will not be released.

Cheers! And thanks!

@Ailrun
Copy link
Contributor

Ailrun commented Feb 12, 2018

@luke-john Please update your snapshots.
It seems this snapshot changes related with microsoft/TypeScript#20705.

@luke-john
Copy link
Collaborator Author

Have just updated the tests, I'm unsure about merging this though as we never worked out why this was causing additional failures #372 (comment). I've tried to reproduce without luck, however have added a test case for this which does not appear to fail.

Also sorry for the huge delay here, I've just relocated to London from Australia and my life has been a bit hectic lately.

@luke-john
Copy link
Collaborator Author

thanks for following this up @Ailrun

@Ailrun
Copy link
Contributor

Ailrun commented Feb 16, 2018

@luke-john it looks like @denis-sokolov miss something (or we miss some updates) since error message includes CssProperties which we just removed in this PR. I will also retry to reproduce, and if it's failed, IMO, we should merge this first and make an issue with needs investigation label.

P.S. I cannot reproduce it.

@Ailrun
Copy link
Contributor

Ailrun commented Feb 16, 2018

@kentcdodds I still cannot merge this.
image
There're no buttons I can click :(.

@kentcdodds
Copy link
Contributor

Oh, that's because you're the one who approved it. Need to have someone else merge it. I guess that can be me! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants