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 error: null not allowed as theme value for WordPressBlocksProvider #1844

Open
1 task done
mdrayer opened this issue Mar 13, 2024 · 3 comments
Open
1 task done

Comments

@mdrayer
Copy link

mdrayer commented Mar 13, 2024

Description

If you provide null as the value for theme in your config for WordPressBlocksProvider, you will get an error if your "strict" flag is set to true.

<WordPressBlocksProvider config={{ blocks, theme: null }}>

Type 'null' is not assignable to type 'BlocksTheme | undefined'.ts(2322)

This is because the current type definition does not include null as a valid type:

export type WordPressBlocksProviderConfig = {
  blocks: { [key: string]: WordPressBlock };
  theme?: BlocksTheme;
};

https://github.com/wpengine/faustjs/blob/canary/packages/blocks/src/components/WordPressBlocksProvider.tsx#L36-L39

To fix, the type should be updated to theme?: BlocksTheme | null.

Steps to reproduce

  1. Get a TypeScript Faust project (e.g. https://github.com/wpengine/faust-scaffold-ts). Set the "strict" flag to true in tsconfig.
  2. Install @faustwp/blocks.
  3. Add WordPressBlocksProvider to your app and attempt to use null as the theme value for your config.
<WordPressBlocksProvider config={{ blocks: {}, theme: null}}>

The Type 'null' is not assignable to type 'BlocksTheme | undefined' error should appear in your TypeScript checks.

Additional context

No response

@faustwp/core Version

3.0.0

@faustwp/cli Version

3.0.0

FaustWP Plugin Version

N/A

WordPress Version

N/A

Additional environment details

This issue is specific to the @faustwp/blocks package, versions 0.3.1 - 4.0.0.

Please confirm that you have searched existing issues in the repo.

  • Yes
@theodesp
Copy link
Member

Thank you @mdrayer. Would you be able to provide a PR for this?

@mdrayer
Copy link
Author

mdrayer commented Mar 15, 2024

@theodesp sure, I can give that a go. Would it be best for me to fork the repo and do a PR that way?

@theodesp
Copy link
Member

theodesp commented Mar 19, 2024

@mdrayer Make sure you fork the repo, make your changes, and open a PR against the Canary branch.

We have a contribution guide:

https://github.com/wpengine/faustjs/blob/canary/CONTRIBUTING.md#instructions-for-contributing-code

You also need to complete a CLA form for first PRs

Contributor License Agreement

All external contributors to WP Engine products must have a signed Contributor License Agreement (CLA) in place before the contribution may be accepted into any WP Engine codebase.

  1. Submit your name and email
  2. 📝 Sign the CLA emailed to you
  3. 📥 Receive copy of signed CLA

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

No branches or pull requests

2 participants