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

Add explicit type declaration to ChakraProvider.defaultProps #6464

Merged
merged 5 commits into from Aug 13, 2022

Conversation

rossng
Copy link
Contributor

@rossng rossng commented Aug 11, 2022

Closes #6463

📝 Description

This PR adds an explicit declaration to chakra-provider.tsx that will forcefully change the declaration output from this:

declare function ChakraProvider({ children, toastOptions, ...restProps }: ChakraProviderProps): JSX.Element;
declare namespace ChakraProvider {
    var defaultProps;
}

to this:

declare function ChakraProvider({ children, toastOptions, ...restProps }: ChakraProviderProps): JSX.Element;
declare namespace ChakraProvider {
    let defaultProps: {
        theme: Theme;
    };
}

I was

⛳️ Current behavior (updates)

The current implementation leaves TypeScript to infer the type that must be emitted for ChakraProvider.defaultProps, which it fails to do. This causes TypeScript builds to fail in strict mode for consumers of @chakra-ui/react.

🚀 New behavior

The new implementation explicitly declares the type that needs to be emitted.

💣 Is this a breaking change (Yes/No):

I don't believe this is a real breaking change, though I guess it could potentially break builds in some edge cases.

📝 Additional Information

I did find alternative ways to do this without the declare namespace, but they require depending on the @chakra-ui/theme-tools package and inline the gigantic theme type into the emitted declaration file.

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2022

🦋 Changeset detected

Latest commit: ff3f328

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@chakra-ui/react Minor
create-react-app-ts Patch
gatsby-starter-default Patch
chakra-nextjs Patch
chakra-nextjs-ts Patch
@chakra-ui/props-docs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 11, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
chakra-ui-storybook ✅ Ready (Inspect) Visit Preview Aug 13, 2022 at 5:12AM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 11, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ff3f328:

Sandbox Source
create-react-app-ts Configuration

@segunadebayo
Copy link
Member

We really want to move away from default props for the most part and just add the default from within the component. If you can refactor the code to do that, that'll be great.

@rossng
Copy link
Contributor Author

rossng commented Aug 11, 2022

Thanks for the review. I've revised the PR - does this match what you were suggesting?

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.

ChakraProvider.defaultProps is implicitly typed any in generated declarations for @chakra-ui/react
2 participants