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

[Typescript] Questions on the styling types #8550

Closed
wcandillon opened this issue Oct 5, 2017 · 4 comments
Closed

[Typescript] Questions on the styling types #8550

wcandillon opened this issue Oct 5, 2017 · 4 comments

Comments

@wcandillon
Copy link
Contributor

I have a question regarding the StyledComponentProps interface. classes is marked as optional even though it shouldn't be if the component is styled using withStyle?

I had a similar typedefinition in my project:

export interface StylingProps<T extends string> {
    classes: { [key in T]: string };
    style?: Partial<CSSProperties>;
    className?: string;
}

Here classes is marked as mandatory as well as it's class names. I was hoping to replace this type with StyledComponentProps but it doesn't seem to be exactly the same. am I missing something?

@wcandillon
Copy link
Contributor Author

I have a similar question with the type of the classes property within StyledComponentProps. Why is it using Partial<>? Should the developer be obligated to provide all the classe definitions?

@wcandillon
Copy link
Contributor Author

Everywhere I have to update my code from:

        const {classes, anotherProp} = this.props;

to

        const {anotherProp} = this.props;
        const classes = this.props.classes as ClassNameMap<Classes>;

What is the best practice?

@pelotom
Copy link
Member

pelotom commented Oct 5, 2017

@wcandillon see the discussion on #8447.

@wcandillon
Copy link
Contributor Author

Thanks a lot I was able to solve my issues.

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

No branches or pull requests

3 participants