Skip to content

Preserve element type through sort/sort_natural filters - #1298

Open
Aryaneefds wants to merge 1 commit into
Shopify:mainfrom
Aryaneefds:fix/sort-filter-type-preservation
Open

Preserve element type through sort/sort_natural filters#1298
Aryaneefds wants to merge 1 commit into
Shopify:mainfrom
Aryaneefds:fix/sort-filter-type-preservation

Conversation

@Aryaneefds

Copy link
Copy Markdown

Fixes #1086.

Problem: media | sort (the single-object-to-array trick) and images | sort both inferred as untyped[] because the docset declares sort as returning an untyped array — the element type was lost.

Fix (TypeSystem.ts, LiquidVariable inference): when the last filter is sort/sort_natural, infer the input type instead of using the docset return type —

  • array input keeps its value type (product[] | sortproduct[])
  • single typed value wraps into an array type (media | sortmedia[]), chain-safe via recursion without the last filter
  • untyped/unknown input falls back to the docset type (no behavior change there)

Tests: 6 new cases in TypeSystem.spec.ts (array preserve, single-value wrap, sort_natural, chained sorts, lookup-type preserve, unknown fallback). Suite: 35 passed, 1 skipped (pre-existing skip).

Fixes Shopify#1086: media | sort lost its type (untyped[]) because the docset
declares sort as returning an untyped array. Infer the input type
instead: arrays keep their value type, single values wrap into a
single-element array type, unknown input falls back to docset.
@Aryaneefds
Aryaneefds requested a review from a team as a code owner September 12, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve doc typing when converting to array

1 participant