refactor: Better types #17

Merged
timharek merged 11 commits from feature-better-type-safety into main 2024-04-02 12:57:30 +00:00
1 changed files with 7 additions and 3 deletions
Showing only changes of commit f4ec8f8d36 - Show all commits

View File

@ -2,11 +2,15 @@ import { FreshContext } from "$fresh/server.ts";
import { parse, toSeconds } from "https://esm.sh/iso8601-duration@2.1.1"; import { parse, toSeconds } from "https://esm.sh/iso8601-duration@2.1.1";
import { nrkRadio, OriginalEpisode } from "../../../../../lib/nrk.ts"; import { nrkRadio, OriginalEpisode } from "../../../../../lib/nrk.ts";
// TODO: This type `OriginalEpisode` is missing stuff. type Chapter = {
function toChapters(episode: OriginalEpisode) { title: string | undefined;
startTime: number | undefined;
};
function toChapters(episode: OriginalEpisode): Chapter[] {
return episode.indexPoints.map((indexPoint) => ({ return episode.indexPoints.map((indexPoint) => ({
title: indexPoint.title, title: indexPoint.title,
startTime: toSeconds(parse(indexPoint.startPoint)), startTime: indexPoint.startPoint ? toSeconds(parse(indexPoint.startPoint)) : undefined,
})); }));
} }