Skip to content

Add SDK type augmentation utilities #1254

@snigdhachoudhury

Description

@snigdhachoudhury

Problem

I noticed there are a bunch of TypeScript type safety issues coming from the OpenFoodFacts SDK types. Right now, they’re being ignored using @ts-expect-error in a few places like ProductHeader.svelte, +page.ts, and +page.svelte.

Some examples:

nutriments field isn’t typed correctly
knowledge_panels_client is being used but isn’t part of the official types
There are some workarounds with UiProduct casting

Because of this, strict TypeScript checks aren’t really working properly, and autocomplete/IDE support also takes a hit

Proposed solution

I tried to fix this by properly handling the types instead of suppressing errors.

  • Created extended product types to better match actual API responses
  • Fixed the nutriments field by introducing a proper Nutriments type
  • Added support for knowledge_panels_client in typing
  • Removed the need for @ts-expect-error in these files

Additional context

The issue seems to come from incomplete type definitions in the OpenFoodFacts SDK (v2.0.0-alpha.29). The API returns more fields than what’s currently typed, which leads to these mismatches.

Part of

Related to improving code quality and type safety across the codebase

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions