Skip to content

Instantly share code, notes, and snippets.

@ikasoba
Created March 5, 2022 09:31
Show Gist options
  • Save ikasoba/12dec133c06c509729f8633c1d00295d to your computer and use it in GitHub Desktop.
Save ikasoba/12dec133c06c509729f8633c1d00295d to your computer and use it in GitHub Desktop.
typescriptで0~(n-1)までの整数値のみ型
type Append<T extends any[],U extends any> = [...T,U]
type range<N extends number,A extends any[]> = {
0:range<N,Append<A,A["length"]>>,
1:A
}[A["length"] extends N ? 1 : 0]
const nums:range<4,[]>=[0,1,2,3]
console.log(nums)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment