Skip to content

Commit 8ee80e9

Browse files
committed
fixed type constrain not working properly for inferred Tail
issue introduced in '4aa61e443886b3327698829aa204a71a723e1f4a'
1 parent c81b67e commit 8ee80e9

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/index.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Compensation
33
type As<T, _Infer extends T> = unknown;
44
type Head<T extends unknown[]> = T[0];
5-
type Tail<T extends unknown[]> = T extends [unknown, ...infer MyTail]
5+
type Tail<T extends unknown[]> = T extends [infer _, ...infer MyTail]
66
? MyTail
77
: never
88
;
@@ -240,10 +240,7 @@ type Groups = (Token & {type: 'groups'})['groups'];
240240
// Indexification (DFS)
241241
// Utils
242242
type FlattenGroups<TGroups extends Groups> = unknown extends AsLinked<TGroups, infer First, infer Rest>
243-
? [First, ...FlattenToken<First['inner']>, ...FlattenGroups<
244-
// @ts-expect-error: TS cannot infer that this extends 'Groups'
245-
Rest
246-
>]
243+
? [First, ...FlattenToken<First['inner']>, ...FlattenGroups<Rest>]
247244
: []
248245
;
249246
type FlattenTokenInternal<TToken extends Token, Limit extends unknown[]> = Limit extends [unknown, ...infer L]
@@ -263,11 +260,7 @@ type IndexGroups<TGroups extends Groups, TIndex extends number> = unknown extend
263260
index: TIndex,
264261
value: Omit<First, 'inner'> & { inner: IndexTokenInternal<First['inner'], Increment<TIndex>> }
265262
},
266-
...IndexGroups<
267-
// @ts-expect-error: TS cannot infer that this extends 'Groups'
268-
Rest,
269-
Add<TIndex, FlattenGroups<[First]>['length'] & number>
270-
>
263+
...IndexGroups<Rest, Add<TIndex, FlattenGroups<[First]>['length'] & number>>
271264
]
272265
: []
273266
;
@@ -316,10 +309,7 @@ type ContextualValue<T extends GroupWithIndex, TValue> = Record<T['index'], {
316309
reference: T['value']
317310
}>;
318311
type UnsetGroups<TGroups extends GroupWithIndexes> = unknown extends AsLinked<TGroups, infer First, infer Rest>
319-
? ContextualValue<First, never> & UnsetToken<First['value']['inner']> & UnsetGroups<
320-
// @ts-expect-error: TS cannot infer that this extends 'GroupWithIndexes'
321-
Rest
322-
>
312+
? ContextualValue<First, never> & UnsetToken<First['value']['inner']> & UnsetGroups<Rest>
323313
: {}
324314
;
325315
type UnsetToken<TToken extends TokenWithIndex> = TToken extends { type: 'alternation' }
@@ -334,10 +324,7 @@ type ContextualizeGroups<TGroups extends GroupWithIndexes> = unknown extends AsL
334324
? UnsetGroups<[First]>
335325
: never
336326
) | (ContextualValue<First, string> & ContextualizeToken<First['value']['inner']>)
337-
) & ContextualizeGroups<
338-
// @ts-expect-error: TS cannot infer that this extends 'GroupWithIndexes'
339-
Rest
340-
>
327+
) & ContextualizeGroups<Rest>
341328
: {}
342329
;
343330
type ContextualizeToken<TToken extends TokenWithIndex> = TToken extends { type: 'alternation' }
@@ -388,11 +375,7 @@ type Remove<Ts extends unknown[], TMatch extends Ts[number]> = unknown extends A
388375
type Flags = ['d', 'g', 'i', 'm', 's', 'u' | 'v', 'y'];
389376
type Flag = Flags[number];
390377
type GetFlagsInternal<T extends string, TFlags extends Flag[]> = unknown extends AsLinked<TFlags, infer First, infer Rest>
391-
? `${Fallback<FirstMatch<First, T>, ''>}${GetFlagsInternal<
392-
T,
393-
// @ts-expect-error: TS cannot infer that this extends 'Flag[]'
394-
Rest
395-
>}`
378+
? `${Fallback<FirstMatch<First, T>, ''>}${GetFlagsInternal<T, Rest>}`
396379
: ''
397380
;
398381
type GetFlags<T extends string> = string extends T
@@ -403,7 +386,7 @@ type AreFlagsValid<TSource extends string, TFlags extends Flag[]> = TSource exte
403386
? First extends TFlags[number]
404387
? AreFlagsValid<
405388
Rest,
406-
// @ts-expect-error: TS cannot infer that this extends 'Flag[]'
389+
// @ts-expect-error: Excessive stack depth
407390
Remove<TFlags, First>
408391
>
409392
: false

0 commit comments

Comments
 (0)