-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
standard css properties for react.d.ts #5089
Conversation
i tryed to add style attribute: style={{display: 'block'}}> but CSSProperties not contains 'display'. As i understand, should populate this interface with snadard css properties?
This seems reasonable to me. However, changes should be made to both react.d.ts and react-global.d.ts. @vsiao Do you know why |
I didn't populate CSSProperties fully because... well, there's a lot of them. It doesn't have to be a complete definition to work (in the context of creating |
I wonder if @stepancar is using the nightly build (TS 1.6) which has this. That could cause an error in this case,. With that in place, you would have to do |
@vsiao, for example: We have interface State{
isClosed: boolean;
} and in render function render(){
return <div style={{display: this.state.isClosed? 'none': 'block'}}></div>
} you'll catch typeError, beacause display isn' exists in |
@stepancar Apologies, I just realized you're using JSX which doesn't have support for angle-bracket type assertion. Try |
@jbrantly thank you! It works. |
I agree. A large point of that fix is to be able to catch typos and such (ex: |
It should at the very least have the same changes applied across the board before a merge. react.d.ts, react-addons.d.ts, and react-global.d.ts. |
It looks fine to merge pending changes to all files. |
@jbrantly, hello! I added additional props to react.d.ts, react-global.d.ts |
I've run into the issue @jbrantly just described with TS 1.6 where keys in object literals must match identifiers listed in interface properties. Given the large number of possible properties, not accounting for vendor-specific properties, an option would be to add a generic index property to CSSProperties as a fallback. This would enable catching of incorrect types passed to numeric properties, but wouldn't catch typos in property names: interface CSSProperties {
flex: number;
display: string;
[index: string]: string | number;
} An alternative would be to list all the standard properties from CSS 3 in CSSProperties and require users to create their own subclassing interfaces for additional properties. Thoughts? |
@robertknight I think the right approach is to list all of the properties so that we get the benefits of TypeScript and the new freshness checking for catching typos. Otherwise we're throwing that benefit away. It's been on my list of things to-do for a while now though so... it's just a matter of someone getting the bandwidth to actually make the change. |
i tryed to add style attribute: style={{display: 'block'}}> but CSSProperties not contains 'display'.
As i understand, should populate this interface with snadard css properties?