Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/supabase/public-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,18 @@ export async function getJobOffersForEdition(edition: string): Promise<Company[]

const companies: Company[] = [];

const offersBySponsor = new Map<string, typeof offers>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The map offersBySponsor is typed using typeof offers, which includes null (since offers can be null if the query fails or returns no data). Since the map only stores actual arrays of offers and never null, typing it with typeof offers is semantically incorrect and can lead to unnecessary null-safety checks or potential compiler errors under strict null checking if the code is refactored.

Using NonNullable<typeof offers> ensures the map's value type is strictly the array type (e.g., JobOffer[]) without null.

Suggested change
const offersBySponsor = new Map<string, typeof offers>();
const offersBySponsor = new Map<string, NonNullable<typeof offers>>();

offers?.forEach((o) => {
const existing = offersBySponsor.get(o.sponsor_id);
if (!existing) {
offersBySponsor.set(o.sponsor_id, [o]);
} else {
existing.push(o);
}
});

sponsors.forEach((sponsor) => {
const sponsorOffers = offers?.filter((o) => o.sponsor_id === sponsor.id) || [];
const sponsorOffers = offersBySponsor.get(sponsor.id) || [];

if (sponsorOffers.length > 0) {
const mappedOffers: JobOffer[] = sponsorOffers.map((o) => ({
Expand Down
Loading