lukePeavey / SplitType

Javascript utility that splits text into lines, words, characters for animation
https://lukepeavey.github.io/SplitType/
558 stars 40 forks source link

Add type support for types property in options #22

Closed StevenJPx2 closed 2 years ago

StevenJPx2 commented 2 years ago

Right now types in the options? parameter does not have any strict typing.

You can leverage template literals to give first-class typing for it:

type ElementSplitType = 'lines' | 'words' | 'chars'
type TypesAgg =
  | ElementSplitType
  | `${ElementSplitType} ${ElementSplitType}`
  | `${ElementSplitType} ${ElementSplitType} ${ElementSplitType}`

This will cover all bases and give excellent autocomplete suggestions.

lukePeavey commented 2 years ago

Good idea, want to submit a pr?

lukePeavey commented 2 years ago

@StevenJPx2 I just tested this out, it works great! I will definitely add this in the next update!

Just out of curiosity, do you know how you would create a similar type for an Array... an array that supports three values (lines, words, chars) in any combination, with autocomplete suggestions?

lukePeavey commented 2 years ago

I'll submit a PR shortly.