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

Documentation incorrect #1148

Open
sjc-gh opened this issue Sep 22, 2023 · 0 comments
Open

Documentation incorrect #1148

sjc-gh opened this issue Sep 22, 2023 · 0 comments
Labels
contribution wanted A maintainer wants help on an issue or pull request documentation A need for improvements or additions to documentation

Comments

@sjc-gh
Copy link

sjc-gh commented Sep 22, 2023

The documentation for some API methods is incorrect or doesn't match the code. For example:

navigateToUrl

https://single-spa.js.org/docs/api#navigatetourl

navigateToUrl(document.querySelector('a')); gives an error in TypeScript:

Argument of type 'HTMLAnchorElement | null' is not assignable to parameter of type 'string | { currentTarget: { href: string; }; preventDefault: any; }'.
Type 'null' is not assignable to type 'string | { currentTarget: { href: string; }; preventDefault: any; }'

See https://github.com/single-spa/single-spa/blob/master/typings/single-spa.d.ts#L207-L212.

document.querySelector('a').addEventListener(singleSpa.navigateToUrl); also gives an error because the first parameter to addEventListener should be an event name. Even when corrected and adding the possible return of null from querySelector, there's still an error in Typescript with the type definition of navigateToUrl not matching the event listener param:

document.querySelector('a')?.addEventListener('click', navigateToUrl);

pathToActiveWhen

https://single-spa.js.org/docs/api#pathtoactivewhen

The documentation claims the return is a function that takes a URL and returns a boolean, however according to the type definition, it takes a Location object:

https://github.com/single-spa/single-spa/blob/master/typings/single-spa.d.ts#L127

It might work in Javascript since Location and URL have the properties in common, but not Typescript. As such, all the examples shown in the documentation give errors in Typescript.

@MilanKovacic MilanKovacic added the documentation A need for improvements or additions to documentation label Sep 26, 2023
@MilanKovacic MilanKovacic added the contribution wanted A maintainer wants help on an issue or pull request label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution wanted A maintainer wants help on an issue or pull request documentation A need for improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants