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 type definition is different from original #931

Closed
jeanverster opened this issue Feb 21, 2022 · 5 comments · Fixed by #967 or ezolenko/rollup-plugin-typescript2#332
Closed

Comments

@jeanverster
Copy link

Hi there! I'm running into an issue where the exported type definition differs from the type definition of the actual component. For instance, if I hover over the Box component where it's being defined, I get the following type definition:

const Box: React.ForwardRefExoticComponent<Pick<BoxProps, keyof CommonProps | "translate" | StandardSystemKeys | "slot" | "title" | "children" | "component" | "sx" | "key" | ... 246 more ... | "onTransitionEndCapture"> & React.RefAttributes<...>>

But after I've run microbundle build the definition for Box is missing all the props:

declare const Box: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<unknown>>;

Any ideas why that might be?

@rschristian
Copy link
Collaborator

A reproduction would help.

Does tsc output correctly?

@jeanverster
Copy link
Author

Apologies, I realise the issue description above wasn't very helpful. For what it's worth I've done a bit more digging, and when I tried to create a minimal repro and all seemed to work as expected, but we are using microbundle in a rush monorepo to bundle components, so when I recreated a simple rush project I could recreate the issue. The repo can be found here.

You may need to globally install @microsoft/rush if you haven't already.. Then to replicate:

  1. In root dir run rush update
  2. Cd into the libraries/components directory and run rushx build and rushx build-tsc and observe the different outputs in lib/Box/Box.d.ts

I do realise this could potentially be some issue with using microbundle in a rush monorepo - but I'm a bit confused as to why that might be. Any insight would be appreciated!

@rschristian
Copy link
Collaborator

Thanks, that helped a lot.

We use rollup-plugin-typescript2 for working with TS, and it doesn't seem like it supports symlinks very well at the moment, see: ezolenko/rollup-plugin-typescript2#234

If you delete node_modules, and reinstall in libraries/components with NPM or Yarn (v1), everything will work as expected.

There's a number of other issues with that plugin in monorepos too (like #808) so maybe I'll take a look and see if there are any alternatives out there that handle some of these things better. TS is quite difficult to bundle correctly, especially in Rollup, so this isn't a criticism of that plugin.

@jeanverster
Copy link
Author

@rschristian awesome, thanks for the heads up. I had no idea about the symlink issues. After switching to yarn instead of pnpm I can confirm that the types are getting bundled correctly 👍 Gonna go ahead and close this as I don't think this is necessarily an issue with microbundle itself

@rschristian
Copy link
Collaborator

I had no idea either, so I'm glad you brought this up.

I'm actually going to reopen this, as I think it's quite useful for tracking and catching other users who run into this. While there's not much we can do here (short of migrating), this might become a more common issue with pnpm gaining some traction recently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants