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

Error TS2305: Module '"react-element-to-jsx-string"' has no exported member 'Options' #514

Closed
leonelgalan opened this issue Jan 20, 2020 · 4 comments · Fixed by #516
Closed
Assignees
Labels

Comments

@leonelgalan
Copy link

storybookjs/addon-jsx fails when updating from 14.1.0 to 14.3.0 with the error above, because the following line:

import reactElementToJSXString, { Options } from 'react-element-to-jsx-string';

I'm not familiar with publishing types, but I believe the error is because related to index.d.ts not exporting ReactElementToJSXStringOptions, perhaps as Options?

@armandabric armandabric self-assigned this Jan 20, 2020
@armandabric
Copy link
Collaborator

Hi @leonelgalan,

When you said that storybookjs/addon-jsx fails, what is failing? The build? or the type checking?

In v14.2, we recently added the index.d.ts files to help TS users: #475. It's possible there is some issue with it.

I think there was an issue with the line:

import reactElementToJSXString, { Options } from 'react-element-to-jsx-string';

We never export the type Options in flow. So I'm sure what was the content of this variable was (and the import should have been import { type Options }).

That said, we should probably export in flow and TS the options type.

@leonelgalan
Copy link
Author

The build fails with the error above:

src/index.tsx:4:35 - error TS2305: Module '"react-element-to-jsx-string"' has no exported member 'Options'.

4 import reactElementToJSXString, { Options } from 'react-element-to-jsx-string';

My wild guess is that flow exported it implicitly, because it was part of the signature of the default function exported.

For TS, this seems to work:

diff --git a/index.d.ts b/index.d.ts
index c2bc46a..83ff4c6 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -13,7 +13,8 @@ declare module 'react-element-to-jsx-string' {
     sortProps?: boolean;
     useFragmentShortSyntax?: boolean;
   }
+  export { ReactElementToJSXStringOptions as Options };

   const reactElementToJSXString: (element: ReactNode, options?: ReactElementToJSXStringOptions) => string;
-  export = reactElementToJSXString;
+  export default reactElementToJSXString;
 }

I was able to use the new filterProps by linking (yarn link) this project and building storybook-addon-jsx.

@armandabric
Copy link
Collaborator

The PR #516 should fix this

@armandabric
Copy link
Collaborator

I just publish react-element-to-jsx-string@14.3.1 with TS type fix. Keep me posted if there is any issue

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

Successfully merging a pull request may close this issue.

2 participants