faustjs icon indicating copy to clipboard operation
faustjs copied to clipboard

TypeScript error: `null` not allowed as `theme` value for WordPressBlocksProvider

Open mdrayer opened this issue 1 year ago • 3 comments

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.

  • [X] Yes

mdrayer avatar Mar 13 '24 19:03 mdrayer

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

theodesp avatar Mar 14 '24 11:03 theodesp

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

mdrayer avatar Mar 15 '24 15:03 mdrayer

@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

theodesp avatar Mar 19 '24 09:03 theodesp

I believe this has been solved by #1986 Feel free to reopen or comment if that's not the case.

moonmeister avatar Jan 21 '25 17:01 moonmeister