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

Exported variable 'Some-Element-withRef' has or is using name 'UNDEFINED_VOID_ONLY' from external module "mono-repo-root/node_modules/@types/react/canary" but cannot be named #3127

Open
PaulSinghDev opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@PaulSinghDev
Copy link

PaulSinghDev commented Apr 16, 2024

Description

When using plate as a package within an Monorepo it seems to have issues passing type verification when the types defined for react/canary are not in the same repo as the Plate library.

Steps to Reproduce

Repo

https://github.com/PaulSinghDev/plate-js-issue

Sandbox

Link to CodeSandbox

Expected Behavior

The app builds

Environment

  • slate: ^0.102.0
  • slate-react: ^0.102.0

Solution

Is to type the elements before exporting them.

Current HrElement:

import React from 'react';
import { cn, withRef } from '@udecode/cn';
import { PlateElement } from '@udecode/plate-common';
import { useFocused, useSelected } from 'slate-react';

export const HrElement = withRef<typeof PlateElement>(
  ({ className, nodeProps, ...props }, ref) => {
    const { children } = props;

    const selected = useSelected();
    const focused = useFocused();

    return (
      <PlateElement ref={ref} {...props}>
        <div className="py-6" contentEditable={false}>
          <hr
            {...nodeProps}
            className={cn(
              'h-0.5 cursor-pointer rounded-sm border-none bg-muted bg-clip-content',
              selected && focused && 'ring-2 ring-ring ring-offset-2',
              className
            )}
          />
        </div>
        {children}
      </PlateElement>
    );
  }
);

After update (compiling):

import React from "react";
import { cn, withRef } from "@udecode/cn";
import { PlateElement } from "@udecode/plate-common";
import { useFocused, useSelected } from "slate-react";

// Stpre a type def
type HrType = typeof PlateElement;

// Provide the typedef for this component
export const HrElement: ReturnType<typeof withRef<HrType>> = withRef<HrType>(
  ({ className, nodeProps, ...props }, ref) => {
    const { children } = props;

    const selected = useSelected();
    const focused = useFocused();

    return (
      <PlateElement ref={ref} {...props}>
        <div className="py-6" contentEditable={false}>
          <hr
            {...nodeProps}
            className={cn(
              "h-0.5 cursor-pointer rounded-sm border-none bg-muted bg-clip-content",
              selected && focused && "ring-2 ring-ring ring-offset-2",
              className
            )}
          />
        </div>
        {children}
      </PlateElement>
    );
  }
);

With the change above it seems to compile

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@PaulSinghDev PaulSinghDev added the bug Something isn't working label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant