Created
April 18, 2025 12:03
-
-
Save nwellis/a401a6915d1518c5142cfb74632bc9d9 to your computer and use it in GitHub Desktop.
Revisions
-
nwellis created this gist
Apr 18, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ export function withType<TElement extends { __type: string }, TType extends TElement["__type"]>( elements: TElement[], type: TType ): Extract<TElement, { __type: TType }>[] { return elements?.filter(element => element.__type === type) as Extract<TElement, { __type: TType }>[] } export function withoutType<TElement extends { __type: string }, TType extends TElement["__type"]>( elements: TElement[], type: TType ): Exclude<TElement, { __type: TType }>[] { return elements?.filter(element => element.__type !== type) as Exclude<TElement, { __type: TType }>[] }