liquid icon indicating copy to clipboard operation
liquid copied to clipboard

[LiquidDoc] Add union types

Open andershagbard opened this issue 6 months ago • 1 comments

Add the possibility to add union types for LiquidDocs.

E.g.

@param {string|number} my_variable - This can be a string or a number.

Use cases:

  • When passing an image aspect attribute, you can manually enter the numeric value as 0.5 or you can enter a string as 1/2, and then have the snippet to the math for you.

  • To be a bit more lax. When passing a width attribute and appending %. E.g. {{ width | append: '%' }}, you wouldn't care if it's a number or a string.

@karreiro (Tagging for visibility)

andershagbard avatar May 31 '25 01:05 andershagbard

To add a usecase, using string literal union types (call it what you want):

A snippet containing a case that renders something based off what parameter is passed. I would like to restrict the parameter to only contain the cases we handle.

@param { 'banner' | 'label' } my_variable - A string that must be either 'banner' or 'label'.

Curzey avatar Jun 04 '25 17:06 Curzey