Skip to content

Commit

Permalink
add array tests for SetRequiredDeep
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomartinet committed Aug 20, 2024
1 parent 033dc39 commit e3c2874
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test-d/set-required-deep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import type {SetRequiredDeep} from '../index';
import {expectAssignable, expectNotAssignable, expectType} from 'tsd';
import type {MergeDeep, OverrideProperties, SetRequired, SetRequiredDeep, Simplify, SimplifyDeep} from '../index';

// Update an optional nested key to required.
declare const variation1: SetRequiredDeep<{a?: number; b?: {c?: string}}, 'b.c'>;
Expand All @@ -20,3 +20,16 @@ expectType<{a: '1'; b: {c: boolean}} | {a: '2'; b: {c: boolean}}>(variation4);
// Set key inside array to required
declare const variation5: SetRequiredDeep<{a?: number; array?: Array<{b?: number}>}, 'array'>;
expectType<{a?: number; array: Array<{b: number}>}>(variation5);

// Set specific key inside array to required
expectAssignable<SetRequiredDeep<{a?: number; array?: Array<{b?: number}>}, 'array.0.b'>>({a: 1, array: [{b: 2}]});
expectNotAssignable<SetRequiredDeep<{a?: number; array?: Array<{b?: number}>}, 'array.0.b'>>({array: [{}]});

// Set only specified keys inside array to required
expectAssignable<SetRequiredDeep<{a?: number; array?: Array<{b?: number; c?: string}>}, `array.${number}.b`>>({array: [{b: 4}]});
expectNotAssignable<SetRequiredDeep<{a?: number; array?: Array<{b?: number; c?: string}>}, `array.${number}.b`>>({array: [{}]});

// Set specific key inside specific array item to required
expectAssignable<SetRequiredDeep<{a?: number; array?: [{b?: number}, {c?: string}]}, 'array.1.c'>>({array: [{}, {c: 'foo'}]});
expectNotAssignable<SetRequiredDeep<{a?: number; array?: [{b?: number}, {c?: string}]}, 'array.1.c'>>({array: [{b: 2}, {}]});

0 comments on commit e3c2874

Please sign in to comment.