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

[Bug]: Typescript error when using plugins in Next.js #59

Open
1 task
pacoorozco opened this issue Aug 2, 2024 · 3 comments
Open
1 task

[Bug]: Typescript error when using plugins in Next.js #59

pacoorozco opened this issue Aug 2, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@pacoorozco
Copy link

What happened?

When executing next build a Typescript error is raised:

   Linting and checking validity of types  ...Failed to compile.

./src/components/MdxComponents/PanoramaViewer/PanoramaViewer.tsx:38:9
Type error: Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[][]' is not assignable to type '(PluginConstructor | [PluginConstructor, any])[]'.
  Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' is not assignable to type 'PluginConstructor | [PluginConstructor, any]'.
    Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' is not assignable to type 'PluginConstructor'.
      Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' provides no match for the signature 'new (viewer: Viewer, config?: any): AbstractPlugin<any>'.

  36 |         height={'100%'}
  37 |         width={'100%'}
> 38 |         plugins={plugins}
     |         ^
  39 |       ></ReactPhotoSphereViewer>
  40 |     </div>
  41 |   );

What should have happened?

It should pass the linter and do the build properly. The code is working properly using next dev.

Code

import { AutorotatePlugin } from '@photo-sphere-viewer/autorotate-plugin';
import dynamic from 'next/dynamic';
import { FC } from 'react';

import styles from '@/styles/documentation.module.scss';

const ReactPhotoSphereViewer = dynamic(
  () =>
    import('react-photo-sphere-viewer').then(
      (mod) => mod.ReactPhotoSphereViewer,
    ),
  {
    ssr: false,
  },
);

interface PanoramaViewerProps {
  src: string;
}

export const PanoramaViewer: FC<PanoramaViewerProps> = ({ src }) => {
  const plugins = [
    [
      AutorotatePlugin,
      {
        autorotateSpeed: '1rpm'
      },
    ],
  ];

  return (
    <div id='panorama-viewer' className={styles.panorama}>
      <ReactPhotoSphereViewer
        src={src}
        height={'100%'}
        width={'100%'}
        plugins={plugins}
      ></ReactPhotoSphereViewer>
    </div>
  );
};

Sandbox Link

No response

Library Version

6.0.0

What operating system are you using?

Ubuntu

What browser are you using?

None

Logs

   Linting and checking validity of types  ...Failed to compile.

./src/components/MdxComponents/PanoramaViewer/PanoramaViewer.tsx:38:9
Type error: Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[][]' is not assignable to type '(PluginConstructor | [PluginConstructor, any])[]'.
  Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' is not assignable to type 'PluginConstructor | [PluginConstructor, any]'.
    Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' is not assignable to type 'PluginConstructor'.
      Type '(typeof AutorotatePlugin | { autorotateSpeed: string; autorotatePitch: string; })[]' provides no match for the signature 'new (viewer: Viewer, config?: any): AbstractPlugin<any>'.

  36 |         height={'100%'}
  37 |         width={'100%'}
> 38 |         plugins={plugins}
     |         ^
  39 |       ></ReactPhotoSphereViewer>
  40 |     </div>
  41 |   );

Interest to fix the bug

  • I would like to fix this bug!
@pacoorozco pacoorozco added the bug Something isn't working label Aug 2, 2024
@pacoorozco
Copy link
Author

I've found a workaround which is adding the plugins directly as an array.

<ReactPhotoSphereViewer
        src={src}
        height={'100%'}
        width={'100%'}
        plugins={[
          [
            AutorotatePlugin,
            {
              autorotateSpeed: '1rpm',
              autorotatePitch: '3deg',
            },
          ],
        ]}
      ></ReactPhotoSphereViewer>

@Elius94
Copy link
Owner

Elius94 commented Aug 5, 2024

hi! have you tried to add a explicit type definition to the array?

@pacoorozco
Copy link
Author

pacoorozco commented Aug 6, 2024 via email

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

2 participants