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

fix: make categories under Feed an optional type #56

Merged
merged 3 commits into from
Mar 31, 2024

Conversation

totto2727
Copy link
Contributor

Feed["categories"] is defined as Category[].
However, it is actually Category[] | undefined.

The process is to assign a value to categories after it is cast to Feed. However, just before that, it is verified with if, and the assignment may be skipped. This validation also indicates to the compiler that it is NonNullable and the assignment to Category[] is allowed in the if statement.

code in the relevant section

rss/src/mappers/mapper.ts

Lines 379 to 384 in ebee31f

if (categories) {
result.categories = categories?.map((category) => ({
term: category.term,
label: category.label,
}));
}

The fundamental solution is to refactor the process with type assertions, but since this would be a major change, only the type definitions are modified in this PR.

The main changes are the following commits

6d98b1f

@MikaelPorttila MikaelPorttila merged commit a0817ec into MikaelPorttila:master Mar 31, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants