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

fix(CompDefaultProps): comp default props type #2065

Merged
merged 5 commits into from Oct 24, 2022
Merged

fix(CompDefaultProps): comp default props type #2065

merged 5 commits into from Oct 24, 2022

Conversation

congyaqwq
Copy link
Contributor

defaultProps passing to useComponentDefaultProps always return an optional type.

ts playground demo

@rtivital
Copy link
Member

Hi @congyaqwq thanks for a PR! Can you please explain what this line means [Key in Extract<keyof T, keyof U>]-? : U[Key] & T[Key]? I've never seen -? such part anywhere else, can you send a link to ts documentation?

@congyaqwq
Copy link
Contributor Author

It means remove optional ? in an object type.

You can remove or add these modifiers by prefixing with - or +. If you don’t add a prefix, then + is assumed.

typescript mapped-types

@congyaqwq congyaqwq closed this Aug 10, 2022
@rtivital
Copy link
Member

@congyaqwq why did you close the PR?

@congyaqwq
Copy link
Contributor Author

Sorry, there was a test case can not pass in useInputProps fn.
typescript does not calc the type.
demo
line 56

  const {
    label,
    description,
    error,
    required,
    classNames,
    styles,
    className,
    unstyled,
    __staticSelector,
    sx,
    errorProps,
    labelProps,
    descriptionProps,
    wrapperProps,
    id,
    size,
    style,
    inputContainer,
    inputWrapperOrder,
    ...others
  } = useComponentDefaultProps(component, defaultProps, props);

the solution I think maybe need to update defaultProps type to {[Key in T]-?: T[Key]}, but It may be a large change. So I close the PR.
I will reopen this PR if I get a new idea!

@congyaqwq congyaqwq reopened this Oct 12, 2022
@rtivital rtivital merged commit 965fb64 into mantinedev:master Oct 24, 2022
@rtivital
Copy link
Member

Thanks!

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.

None yet

2 participants