Skip to content

Instantly share code, notes, and snippets.

@vko-online
Last active May 31, 2022 17:02
Show Gist options
  • Save vko-online/5cd38dab473e70886bc6d59bb6bce59a to your computer and use it in GitHub Desktop.
Save vko-online/5cd38dab473e70886bc6d59bb6bce59a to your computer and use it in GitHub Desktop.
/*interface BarData {
day1: number;
day2: number;
...
day30: number;
}*/
type LessThan<N extends number, A extends number[] = []> =
N extends A['length'] ? A[number] : LessThan<N, [...A, A['length']]>;
type OneToThirty = Exclude<LessThan<31>, 0>;
interface BarData extends Record<`day${OneToThirty}`, number> { }
function foo(bar: BarData) {
bar.day14 = 3;
bar.day100 = 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment