Skip to content

Commit

Permalink
Rename _UnionToTuple type and type test description
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Dec 23, 2024
1 parent 3e6c7d2 commit 75a68a8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 70 deletions.
135 changes: 68 additions & 67 deletions library/src/methods/keyof/keyof.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,73 +54,74 @@ describe('keyof', () => {
});
});

test('should not trigger an error when object schemas contain many keys', () => {
const schema = keyof(
object({
k00: unknown(),
k01: unknown(),
k02: unknown(),
k03: unknown(),
k04: unknown(),
k05: unknown(),
k06: unknown(),
k07: unknown(),
k08: unknown(),
k09: unknown(),
k10: unknown(),
k11: unknown(),
k12: unknown(),
k13: unknown(),
k14: unknown(),
k15: unknown(),
k16: unknown(),
k17: unknown(),
k18: unknown(),
k19: unknown(),
k20: unknown(),
k21: unknown(),
k22: unknown(),
k23: unknown(),
k24: unknown(),
k25: unknown(),
k26: unknown(),
k27: unknown(),
k28: unknown(),
k29: unknown(),
k30: unknown(),
k31: unknown(),
k32: unknown(),
k33: unknown(),
k34: unknown(),
k35: unknown(),
k36: unknown(),
k37: unknown(),
k38: unknown(),
k39: unknown(),
k40: unknown(),
k41: unknown(),
k42: unknown(),
k43: unknown(),
k44: unknown(),
k45: unknown(),
k46: unknown(),
k47: unknown(),
k48: unknown(),
k49: unknown(),
k50: unknown(),
k51: unknown(),
k52: unknown(),
k53: unknown(),
k54: unknown(),
k55: unknown(),
k56: unknown(),
k57: unknown(),
k58: unknown(),
k59: unknown(),
k60: unknown(),
})
);
expectTypeOf(schema).toEqualTypeOf<
test('should not trigger TS error for many keys', () => {
expectTypeOf(
keyof(
object({
k00: unknown(),
k01: unknown(),
k02: unknown(),
k03: unknown(),
k04: unknown(),
k05: unknown(),
k06: unknown(),
k07: unknown(),
k08: unknown(),
k09: unknown(),
k10: unknown(),
k11: unknown(),
k12: unknown(),
k13: unknown(),
k14: unknown(),
k15: unknown(),
k16: unknown(),
k17: unknown(),
k18: unknown(),
k19: unknown(),
k20: unknown(),
k21: unknown(),
k22: unknown(),
k23: unknown(),
k24: unknown(),
k25: unknown(),
k26: unknown(),
k27: unknown(),
k28: unknown(),
k29: unknown(),
k30: unknown(),
k31: unknown(),
k32: unknown(),
k33: unknown(),
k34: unknown(),
k35: unknown(),
k36: unknown(),
k37: unknown(),
k38: unknown(),
k39: unknown(),
k40: unknown(),
k41: unknown(),
k42: unknown(),
k43: unknown(),
k44: unknown(),
k45: unknown(),
k46: unknown(),
k47: unknown(),
k48: unknown(),
k49: unknown(),
k50: unknown(),
k51: unknown(),
k52: unknown(),
k53: unknown(),
k54: unknown(),
k55: unknown(),
k56: unknown(),
k57: unknown(),
k58: unknown(),
k59: unknown(),
k60: unknown(),
})
)
).toEqualTypeOf<
PicklistSchema<
[
'k00',
Expand Down
6 changes: 3 additions & 3 deletions library/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ export type UnionToIntersect<TUnion> =
*
* For more information: {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#tail-recursion-elimination-on-conditional-types}
*/
type _UnionToTuple<TUnion, TResult extends unknown[]> =
type UnionToTupleHelper<TUnion, TResult extends unknown[]> =
UnionToIntersect<
TUnion extends never ? never : () => TUnion
> extends () => infer TLast
? _UnionToTuple<Exclude<TUnion, TLast>, [TLast, ...TResult]>
? UnionToTupleHelper<Exclude<TUnion, TLast>, [TLast, ...TResult]>
: TResult;

/**
* Converts union to tuple type.
*/
export type UnionToTuple<TUnion> = _UnionToTuple<TUnion, []>;
export type UnionToTuple<TUnion> = UnionToTupleHelper<TUnion, []>;

/**
* Checks if a type is `any`.
Expand Down

0 comments on commit 75a68a8

Please sign in to comment.