-
Notifications
You must be signed in to change notification settings - Fork 208
Typescript fails on Div and Button elements, if you give the onClick attribute a function as argument #353
Comments
Hm... that's weird. I will investigate this. |
Any updates on this? |
Actually, const x: : CSSProperties | ExtraGlamorousProps | React.HTMLProps<HTMLButtonElement> {
css: buttonStyle,
onClick: () => console.log('Hello')
}
<Button {...x} >FileError</Button> is works in your example repo, so the problem may be in React typing (or TS itself), not in Glamorous... |
Glamorous React.SFC<CSSProperties | ExtraGlamorousProps | React.HTMLProps<HTMLButtonElement>> |
So what does this mean exactly? Does it mean, that if you want to attach an onClick function to a button element, this can only be done with a with the object syntax you have shown in your previous reply? |
@Vanluren Sorry for delay. I'm little busy now days...
and of course this fails. Furthermore, instantiating this type is almost impossible. So your suggestion is one solution for this problem, but... what I'm afraid of is adding @luke-john How about your opinion? Is adding |
Thank @Vanluren for the detailed issue and @Ailrun for looking into this already. I really enjoy how friendly and helpful people are on this project 💯. Apologies for my lack of attention here, having a look at this I think this would be solved by having the named built in glamorous components use Re looking at the types though after some time away, there's a few things that could be simplified around the place 🙂. I won't have time to look at any of this until next week at the earliest as I'm off on holidays 🍷☀️. As a temporary measure to get typesafety without asserting to an any you could do something like follows. import { CSSProperties, CSSPropertiesComplete, ExtraGlamorousProps, Button } from 'glamorous';
type TmpButton = React.StatelessComponent<
React.HTMLProps<HTMLButtonElement> & ExtraGlamorousProps & CSSPropertiesComplete
>
const TmpButton = Button as TmpButton
...
<Button css={ buttonStyle } onClick={() => Raven.lastEventId() && Raven.showReportDialog()}>
File Report
</Button> |
When this is fixed, glamorous might be the best css in ts package I've seen. |
@luke-john is there anything I can assist you with on this matter? :) We are unfortunately also experiencing the same issue with the |
@JReinhold Actually, this occurs in every component, using it with the properties that requires other than |
Apologies for the lack of action on this issue. This may be solved by #372 (assuming that works 😄). |
We've just upgraded to the latest glamorous and #372 does not solve the issue :( |
This project is now in an unmaintained status. Please see the README for more information. |
glamorous
version: 4.5.0glamor
version: 2.20.40react
version: 16.0.0typescript
version: 2.6.1, 2.53Relevant code.
What you did:
I tried to give a glamorous Div and a Button Element an onClick attribute with a Function as argument
What happened:
The following error is displayed:
Reproduction:
I was not able to reproduce the problem using Stackblitz, but if you clone this repo
The issue is present in the
src/index.tsx
fileProblem description:
When the glamorous 'Button' element is given an the onClick attribute, typescript fails
Suggested solution:
If you change the CSSPropertiesLossy [glamorous/typings/css-properties.d.ts(l.1921)] interface to allow functions as a type, the error is not displayed, like so:
The text was updated successfully, but these errors were encountered: