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

upkeep: Add TS support for Optional component #298

Merged
merged 9 commits into from
Mar 11, 2024
10 changes: 9 additions & 1 deletion components/optional/index.js → components/optional/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import PropTypes from 'prop-types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think that as part of converting something to TypeScript it makes sense to get rid of all the PropTypes stuff.

import { useBlockEditContext } from '@wordpress/block-editor';

export const Optional = ({ value, children }) => {
interface OptionalProps {
value?: string | number | boolean;
children: React.ReactNode;
}

export const Optional: React.FC<OptionalProps> = ({
value,
Sidsector9 marked this conversation as resolved.
Show resolved Hide resolved
children,
}): boolean | React.ReactNode => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need / want to explicitly type the return type of every function. If something can be inferred I would rather just leave it up to the compiler

const { isSelected } = useBlockEditContext();
return (isSelected || !!value) && children;
};
Expand Down
Loading