Skip to content

Commit 545d725

Browse files
authored
fix: order of generic types for param of createInput (#31)
1 parent a02645b commit 545d725

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/core/internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface Input<V extends string, G extends string = never> {
5656
}
5757

5858
export const createInput = <Value extends string, Groups extends string = never>(
59-
s: Value | Input<Groups, Value>
59+
s: Value | Input<Value, Groups>
6060
): Input<Value, Groups> => {
6161
return {
6262
toString: () => s.toString(),

test/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ describe('inputs', () => {
3131
it('createInput serializes to string', () => {
3232
expect(`${createInput('\\s')}`).toEqual('\\s')
3333
})
34+
it('type infer group names when nesting createInput', () => {
35+
expectTypeOf(createRegExp(createInput(exactly('\\s').as('groupName')))).toEqualTypeOf<
36+
MagicRegExp<'/(?<groupName>\\s)/', 'groupName', never>
37+
>()
38+
})
3439
it('any', () => {
3540
const regExp = createRegExp(anyOf('foo', 'bar'))
3641
expect(regExp).toMatchInlineSnapshot('/\\(foo\\|bar\\)/')

0 commit comments

Comments
 (0)