Skip to content

Instantly share code, notes, and snippets.

@JakeSidSmith
Last active November 28, 2025 18:30
Show Gist options
  • Select an option

  • Save JakeSidSmith/c70ddb43f6e8578fae4821a6b22ebf1a to your computer and use it in GitHub Desktop.

Select an option

Save JakeSidSmith/c70ddb43f6e8578fae4821a6b22ebf1a to your computer and use it in GitHub Desktop.
Type assertions for items in an array
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] as const;
type List = typeof list;
type CheckListItems<Items extends readonly number[]> = Items extends readonly [
infer First,
...infer Rest,
]
? First extends 3
? 'fail'
: Rest extends readonly number[]
? CheckListItems<Rest>
: never
: 'pass';
type Result = CheckListItems<List>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const assertPass = <T extends 'pass'>() => null;
assertPass<CheckListItems<List>>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment