Skip to content

Commit

Permalink
Refactor binary type implementation for improved readability and perf…
Browse files Browse the repository at this point in the history
…ormance
  • Loading branch information
jinhuid committed Jun 2, 2024
1 parent e6cd6bf commit 2a9c933
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/types/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export type NoneBinary<T extends string, _T = T> = T extends `${"1" | "0"}${infe
: never

export type isBinaryString<T extends string> = NoneBinary<T> extends never ? never : T

export type Binary<
T extends number,
R extends string = "",
Arr extends string[] = []
> = Arr["length"] extends T ? R : Binary<T, `${R}${"0" | "1"}`, [...Arr, ""]>
8 changes: 1 addition & 7 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { isBinaryString } from "./helper"
import { Binary, isBinaryString } from "./helper"

export type BinaryString<T extends BrickStruct> = {
[K in keyof T]: isBinaryString<T[K]>
}

// type a = BinaryString<("00" | "10" | "01" | "11")[]>

export type Binary<
T extends number,
R extends string = "",
Arr extends string[] = []
> = Arr["length"] extends T ? R : Binary<T, `${R}${"0" | "1"}`, [...Arr, ""]>

export type Struct<
T extends number,
R extends any[] = []
Expand Down

0 comments on commit 2a9c933

Please sign in to comment.