You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added the announcements option as described in the readme:
{announcements: {'en-US': {visit: 'Navigated to: {title}',url: 'New page at {url}'},'de-DE': {visit: 'Navigiert zu: {title}',url: 'Neue Seite unter {url}'},'*': {visit: '{title}',url: '{url}'}}}
What actually happened? 😵💫
When I do that, typescript complains since it expects the default visit and url parameters to exist at the top level of the option, like this:
{announcements: {'en-US': {visit: 'Navigated to: {title}',url: 'New page at {url}'},'de-DE': {visit: 'Navigiert zu: {title}',url: 'Neue Seite unter {url}'},visit: '{title}',url: '{url}'}}
The implementation looks like it should work as described in the documentation. So we should probably change the type of the option from this:
/** Translations of announcements, keyed by language. */typeAnnouncementTranslations={[lang: string]: Announcements;}&{[keyinkeyofAnnouncements]: string;};
To this:
/** Translations of announcements, keyed by language. */typeAnnouncementTranslations={[lang: string]: Announcements;};
Also, this looks redundant to me:
constlang=document.documentElement.lang||'*';// @ts-expect-error: indexing is messyconsttemplates: Announcements=announcements[lang]||announcements['*']||announcements;
lang has already a fallback of *, so we should be able to get away with this, shouldn't we?
constlang=document.documentElement.lang||'*';// @ts-expect-error: indexing is messyconsttemplates: Announcements=announcements[lang]||announcements;
Overall it looks like this could use some cleanup. Happy to take care of it after #44 has landed, to avoid merge conflicts.
I have provided all necessary information to the best of my knowledge
The text was updated successfully, but these errors were encountered:
hirasso
changed the title
[Bug]: announcements is either wrong in the documentation or in the implementation
[Bug]: AnnouncementTranslations has the wrong type signature
Apr 1, 2024
@hirasso Nice catch. The types definitely look outdated. As to the template fallbacks, not sure if there was a specific edge case I had in mind or if it was just caution turning into paranoia 🤡 So yes, let's clean this up! Although I think we can do that independently of or even before that PR. Who knows if that code turns out to be a viable strategy, and improving the types shouldn't conflict with any of the work on that branch.
What did you expect? 🧐
I added the
announcements
option as described in the readme:What actually happened? 😵💫
When I do that, typescript complains since it expects the default
visit
andurl
parameters to exist at the top level of the option, like this:The implementation looks like it should work as described in the documentation. So we should probably change the type of the option from this:
To this:
Also, this looks redundant to me:
lang
has already a fallback of*
, so we should be able to get away with this, shouldn't we?Overall it looks like this could use some cleanup. Happy to take care of it after #44 has landed, to avoid merge conflicts.
Swup and plugin versions 📝
What browsers are you seeing the problem on? 🧭
No response
Relevant log output 🤓
No response
URL to minimal reproduction 🔗
n/a
Checked all these? 📚
The text was updated successfully, but these errors were encountered: