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

Typing issue when returning relation properties #300

Open
SalahAdDin opened this issue Feb 28, 2024 · 0 comments
Open

Typing issue when returning relation properties #300

SalahAdDin opened this issue Feb 28, 2024 · 0 comments

Comments

@SalahAdDin
Copy link

SalahAdDin commented Feb 28, 2024

So, we have the following database:

const db = factory({
  article: {
    id: primaryKey(() => _articleId++),
    title: () => title,
    slug: () => faker.helpers.slugify(title),
    author: nullable(manyOf("author")),
    thumbnail: oneOf("image"),
    category: oneOf("category"),
    createdDate: () => faker.date.anytime(),
    publishedDate: () => faker.date.anytime(),
    introduction: () => faker.lorem.text(),
    content: {
      // TODO: https://github.com/mswjs/data/issues/299
      root: () => mockRichText(),
    },
    hero: {
      url: () => faker.image.url({ width, height }),
      alt: () => faker.lorem.text(),
      width: () => width,
      height: () => height,
      caption: {
        source: () => faker.lorem.word(),
        description: () => faker.lorem.text(),
      },
    },
    // content: () => ({ root: () => mockRichText() }),
    source: nullable(() => faker.lorem.word()),
    tags: () => mockArray(6, () => faker.lorem.word()),
    continue: oneOf("relatedArticle"),
    related: nullable(manyOf("relatedArticle")),
  },
...
  category: {
    id: primaryKey(() => _categoryId++),
    title: () => categoryTitle,
    slug: () => faker.helpers.slugify(categoryTitle),
  },
...
});

And we want to implement a function to return all articles' slug and their categories' slugs as well:

export const articlePaths = () =>
  db.article.findMany({}).map((a) => ({
    category: a.category.slug,
    slug: a.slug,
  }));

Unfortunately, it fails on typing:
image

Why is this?

When assigning only the category, it does not give any issue.

It should not give any issue when getting relation properties.

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

1 participant