Skip to content

Commit fc3e203

Browse files
committed
fix: decrease type complexity somewhat
1 parent e57b322 commit fc3e203

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/core/inputs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Input } from './internal'
1+
import type { CharInput, Input } from './internal'
22
import { createInput } from './internal'
33
import type { EscapeChar } from './types/escape'
44
import type { Join } from './types/join'
@@ -14,7 +14,7 @@ function createCharInput <T extends string>(raw: T) {
1414
const input = createInput(`[${raw}]`)
1515
const from = <From extends string, To extends string>(charFrom: From, charTo: To) => createCharInput(`${raw}${escapeCharInput(charFrom)}-${escapeCharInput(charTo)}`)
1616
const orChar = Object.assign((<T extends string>(chars: T) => createCharInput(`${raw}${escapeCharInput(chars)}`)), { from })
17-
return Object.assign(input, { orChar, from })
17+
return Object.assign(input, { orChar, from }) as CharInput<T>
1818
}
1919

2020
function escapeCharInput <T extends string>(raw: T) {

src/core/internal.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { exactly } from './inputs'
2+
import { EscapeChar } from './types/escape'
23
import type { Join } from './types/join'
34
import type { InputSource, MapToCapturedGroupsArr, MapToGroups, MapToValues } from './types/sources'
45
import type { IfUnwrapped } from './wrap'
@@ -134,6 +135,11 @@ export interface Input<
134135
toString: () => string
135136
}
136137

138+
export interface CharInput<T extends string> extends Input<`[${T}]`> {
139+
orChar: (<Or extends string>(chars: Or) => CharInput<`${T}${EscapeChar<Or>}`>) & CharInput<T>
140+
from: <From extends string, To extends string>(charFrom: From, charTo: To) => CharInput<`${T}${EscapeChar<From>}-${EscapeChar<To>}`>
141+
}
142+
137143
export function createInput<
138144
Value extends string,
139145
Groups extends string = never,

0 commit comments

Comments
 (0)