Created
August 20, 2020 03:48
-
-
Save iFwu/11ec737e01994920430179f85f409143 to your computer and use it in GitHub Desktop.
This file contains 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
import {Number} from "ts-toolbelt" | |
type Even_<a extends string> = { | |
0: true, | |
1: false, | |
2: Even_<Number.Minus<a, "2">> | |
}[a extends "0" ? 0 : a extends "1" ? 1 : 2] | |
type Even<a extends number> = a extends unknown ? Even_<Number.NumberOf<a>> : never | |
type AssertEven<a extends any[]> = Even<a["length"]> extends true ? a : unknown | |
type A = AssertEven<[1,2,3]> // unknown | |
type B = AssertEven<[1,2,3,4]> // [1,2,3,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment