Created
March 5, 2022 09:31
-
-
Save ikasoba/12dec133c06c509729f8633c1d00295d to your computer and use it in GitHub Desktop.
typescriptで0~(n-1)までの整数値のみ型
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 characters
| 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