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

@astrojs/rss Typescript error for pagesGlobToRssItems when using strictest tsconfig #6590

Closed
1 task done
aivarsliepa opened this issue Mar 18, 2023 · 1 comment · Fixed by #6614
Closed
1 task done
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@aivarsliepa
Copy link
Contributor

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Windows

What browser are you using?

Chrome

Describe the Bug

@astrojs/rss version 2.3.0

This affects only code editor. CLI build still passes.

By using Typescript with strictest tsconfig for RSS generation (rss.xml.ts instead of rss.xml.js), there is a type error just by using code from the official tutorial and docs.

Problem is that return type from resolved pagesGlobToRssItems() does not satisfy RSSOptions.items.
Apparently it's because of exactOptionalPropertyTypes: true tsconfig flag.
RSSFeedItem.content type is content?: string; and corresponding part of return type of pagesGlobToRssItems is content?: string | undefined.

If I modify RSSFeedItem.content type in @astrojs/rss/dist/index.d.ts to content?: string | undefined, the error goes away.

import rss, { pagesGlobToRssItems } from "@astrojs/rss";

export async function get() {
  return rss({
    title: "Astro Learner | Blog",
    description: "My journey learning Astro",
    site: "https://my-blog-site.netlify.app",
    items: await pagesGlobToRssItems(import.meta.glob("./**/*.md")),
    customData: `<language>en-us</language>`,
  });
}
Type '{ description?: string | undefined; customData?: string | undefined; draft?: boolean | undefined; content?: string | undefined; title: string; pubDate: Date; link: string; }[]' is not assignable to type 'Record<string, (...args: unknown[]) => Promise<any>> | RSSFeedItem[]'.
  Type '{ description?: string | undefined; customData?: string | undefined; draft?: boolean | undefined; content?: string | undefined; title: string; pubDate: Date; link: string; }[]' is not assignable to type 'RSSFeedItem[]'.
    Type '{ description?: string | undefined; customData?: string | undefined; draft?: boolean | undefined; content?: string | undefined; title: string; pubDate: Date; link: string; }' is not assignable to type 'RSSFeedItem' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'content' are incompatible.
        Type 'string | undefined' is not assignable to type 'string'.
          Type 'undefined' is not assignable to type 'string'.ts(2322)
index.d.ts(16, 5): The expected type comes from property 'items' which is declared here on type 'RSSOptions'

Link to Minimal Reproducible Example

https://stackblitz.com/edit/node-h2jxcq?file=src%2Fpages%2Frss.xml.ts

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Mar 20, 2023

If I modify RSSFeedItem.content type in @astrojs/rss/dist/index.d.ts to content?: string | undefined, the error goes away.

That sounds good to me. Feel free to send a PR if you'd like!

@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants