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

fullpage_api doesn't exist on window #404

Open
devAdrish opened this issue Mar 22, 2023 · 7 comments
Open

fullpage_api doesn't exist on window #404

devAdrish opened this issue Mar 22, 2023 · 7 comments

Comments

@devAdrish
Copy link

Description

I am using Next.js and typescript. When I try to access fullpage_api, it gives me following error:
'Property 'fullpage_api' does not exist on type 'Window & typeof globalThis'

image

Although it works when running locally, build fails.

image

Versions

Fullpage Version 0.1.36

@alvarotrigo
Copy link
Owner

Where are you trying to execute it?

If you are inside the render function of the fullpage component you can use fullpageApi instead.

@alvarotrigo
Copy link
Owner

Can you try adding this on /types/index.d.ts on the react-fullpage component folder and let me know if it fixes it for you?

declare global {
    interface Window {
        fullpage_api:any;
    }
}

@devAdrish
Copy link
Author

Did try this, fullpage-api becomes undefined.
And yes, works inside the render function, but should be available outside of it.
Can you not export this api from the package so one can import it and use it.
Y'know something like import { fullpage-api } from '@fullpage/react-fullpage.

@alvarotrigo
Copy link
Owner

Did try this, fullpage-api becomes undefined.

It's with underscore: fullpage_api

@alvarotrigo
Copy link
Owner

Can you not export this api from the package so one can import it and use it.

I'll be happy to merge a pull request if you think that's an option.

Note however that the variable window.fullpage_api is created dynamically once fullpage.js gets initialized, so it just doesn't exist before this step.

@cmswalker what are your thoughts on this?

@denisdanielyan
Copy link

Hi Everyone,

I am quite late to the game. @alvarotrigo I think the problem is, in a typescript world, you have to do one of two things which are both problematic from a developer standpoint:

  1. use the prop fullpageApi in the render function -> this limits the usage of the api from content within
  2. use the prop window.fullpage_api which is not defined/exported -> dev needs to make a type declaration of window.fullpage_api himself

So in my mind the simple solution is to export fullpage_api as a variable from within the library. This way developers do not need to know about the inner workings of fullpage.js and can just use the library (in typescript) the way they expect it.

@alvarotrigo
Copy link
Owner

@denisdanielyan if that's possible, that sounds great!
Would you be able to provide a PR with the changes?

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

No branches or pull requests

3 participants