fix(mobile): handle durationInSeconds format
Same as #3148
Thank you for your contribution. We will review it promptly.
@kovsu is attempting to deploy a commit to the RSS3 Team on Vercel.
A member of the Team first needs to authorize it.
Suggested PR Title:
fix(entry-list): improve duration calculation handling
Change Summary: Enhanced duration calculation by handling string format and added a utility function.
Code Review:
Code Review
File: apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx
-
Line 8:
// @ts-expect-error durationInSeconds is string-
Issue: Using
@ts-expect-errorsuppresses TypeScript's type checking without properly addressing the underlying issue or providing a clear explanation. This could lead to unpredictable bugs ifdurationInSecondsis not handled properly as a string or number. -
Recommendation: Instead of suppressing the error, explicitly handle the type conversion with a type guard or a more robust type-checking mechanism to ensure the variable is correctly validated and processed. For example:
Avoid relying onif (typeof durationInSeconds === 'string') { durationInSeconds = formatTimeToSeconds(durationInSeconds); } else if (typeof durationInSeconds !== 'number') { durationInSeconds = 0; // Handle unexpected cases gracefully }@ts-expect-errorunless absolutely necessary and there is no safer alternative.
-
Issue: Using
-
Line 6:
durationInSeconds = attachments ? attachments[0]?.duration_in_seconds : 0-
Issue: The existing code assumes that
attachments[0]?.duration_in_secondsis either a string, a number, orundefined, but it lacks a comprehensive validation for unexpected data. Ifduration_in_secondscontains an invalid or unexpected value (e.g., an object or an array), it could lead to runtime errors. -
Recommendation: Add stricter input validation for
attachments[0]?.duration_in_secondsto ensure it can only be a string, a number, orundefined. For instance:const duration = attachments ? attachments[0]?.duration_in_seconds : 0; if (typeof duration !== 'string' && typeof duration !== 'number') { durationInSeconds = 0; // Fallback for invalid data } else { durationInSeconds = typeof duration === 'string' ? formatTimeToSeconds(duration) : duration; }
-
Issue: The existing code assumes that
Summary of Proposed Changes
- Replace
@ts-expect-errorwith explicit type checking and type guards. - Add robust validation for the
attachments[0]?.duration_in_secondsdata to account for unexpected formats.
These changes will ensure type safety, improve code readability, and prevent runtime errors caused by malformed or unexpected data.
Let me know if further assistance is needed!
Thank you @kovsu for your contribution! 🎉
Your pull request has been merged and we really appreciate your help in making this project better. We hope to see more contributions from you in the future! 💪