-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43f59e0
commit d76a9ca
Showing
2 changed files
with
52 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,38 @@ | ||
import { expectType } from "tsd"; | ||
import type { SetRequiredDeep } from "../index"; | ||
import {expectType} from 'tsd'; | ||
import type {SetRequiredDeep} from '../index'; | ||
|
||
// Set nested key to required | ||
declare const variation1: SetRequiredDeep< | ||
{ a?: number; b?: { c?: string } }, | ||
"b.c" | ||
>; | ||
expectType<{ a?: number; b?: { c: string } }>(variation1); | ||
declare const variation1: SetRequiredDeep<{a?: number; b?: {c?: string}}, 'b.c'>; | ||
expectType<{a?: number; b?: {c: string}}>(variation1); | ||
|
||
// Set key to required but not nested keys if not specified | ||
declare const variation2: SetRequiredDeep< | ||
{ a?: number; b?: { c?: string } }, | ||
"b" | ||
>; | ||
expectType<{ a?: number; b: { c?: string } }>(variation2); | ||
declare const variation2: SetRequiredDeep<{a?: number; b?: {c?: string}}, 'b'>; | ||
expectType<{a?: number; b: {c?: string}}>(variation2); | ||
|
||
// Set root key to required | ||
declare const variation3: SetRequiredDeep< | ||
{ a?: number; b?: { c?: string } }, | ||
"a" | ||
>; | ||
expectType<{ a: number; b?: { c?: string } }>(variation3); | ||
declare const variation3: SetRequiredDeep<{a?: number; b?: {c?: string}}, 'a'>; | ||
expectType<{a: number; b?: {c?: string}}>(variation3); | ||
|
||
// Keeps required key as required | ||
declare const variation4: SetRequiredDeep< | ||
{ a: number; b?: { c?: string } }, | ||
"a" | ||
>; | ||
expectType<{ a: number; b?: { c?: string } }>(variation4); | ||
declare const variation4: SetRequiredDeep<{a: number; b?: {c?: string}}, 'a'>; | ||
expectType<{a: number; b?: {c?: string}}>(variation4); | ||
|
||
// Set key to required in a union. | ||
declare const variation5: SetRequiredDeep< | ||
{ a?: "1"; b?: { c?: boolean } } | { a?: "2"; b?: { c?: boolean } }, | ||
"a" | ||
>; | ||
expectType<{ a: "1"; b?: { c?: boolean } } | { a: "2"; b?: { c?: boolean } }>( | ||
variation5, | ||
); | ||
declare const variation5: SetRequiredDeep<{a?: '1'; b?: {c?: boolean}} | {a?: '2'; b?: {c?: boolean}}, 'a'>; | ||
expectType<{a: '1'; b?: {c?: boolean}} | {a: '2'; b?: {c?: boolean}}>(variation5); | ||
|
||
// Set array key to required | ||
declare const variation6: SetRequiredDeep<{ a?: Array<{ b?: number }> }, "a">; | ||
expectType<{ a: Array<{ b?: number }> }>(variation6); | ||
declare const variation6: SetRequiredDeep<{a?: Array<{b?: number}>}, 'a'>; | ||
expectType<{a: Array<{b?: number}>}>(variation6); | ||
|
||
// Set key inside array to required | ||
declare const variation7: SetRequiredDeep< | ||
{ a?: Array<{ b?: number }> }, | ||
`a.${number}.b` | ||
>; | ||
expectType<{ a?: Array<{ b: number }> }>(variation7); | ||
declare const variation7: SetRequiredDeep<{a?: Array<{b?: number}>}, `a.${number}.b`>; | ||
expectType<{a?: Array<{b: number}>}>(variation7); | ||
|
||
// Set only specified keys inside array to required | ||
declare const variation8: SetRequiredDeep< | ||
{ a?: Array<{ b?: number; c?: string }> }, | ||
`a.${number}.b` | ||
>; | ||
expectType<{ a?: Array<{ b: number; c?: string }> }>(variation8); | ||
declare const variation8: SetRequiredDeep<{a?: Array<{b?: number; c?: string}>}, `a.${number}.b`>; | ||
expectType<{a?: Array<{b: number; c?: string}>}>(variation8); | ||
|
||
// Can set both root and nested keys to required | ||
declare const variation9: SetRequiredDeep< | ||
{ a?: number; b?: { c?: string } }, | ||
"b" | "b.c" | ||
>; | ||
expectType<{ a?: number; b: { c: string } }>(variation9); | ||
declare const variation9: SetRequiredDeep<{a?: number; b?: {c?: string}}, 'b' | 'b.c'>; | ||
expectType<{a?: number; b: {c: string}}>(variation9); |