Skip to content

Commit 925327f

Browse files
authored
Merge pull request Automattic#14968 from forivall/forivall/improve-goto-definition
types: improve goto definition for inferred schema definitions
2 parents 830b010 + 5c003f8 commit 925327f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

types/inferschematype.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ type RequiredPathKeys<T, TypeKey extends string = DefaultTypeKey> = {
146146
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
147147
* @returns a record contains required paths with the corresponding type.
148148
*/
149-
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> = {
150-
[K in RequiredPathKeys<T, TypeKey>]: T[K];
151-
};
149+
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> = Pick<
150+
{ -readonly [K in keyof T]: T[K] },
151+
RequiredPathKeys<T, TypeKey>
152+
>;
152153

153154
/**
154155
* @summary A Utility to obtain schema's optional path keys.
@@ -166,9 +167,10 @@ type OptionalPathKeys<T, TypeKey extends string = DefaultTypeKey> = {
166167
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
167168
* @returns a record contains optional paths with the corresponding type.
168169
*/
169-
type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> = {
170-
[K in OptionalPathKeys<T, TypeKey>]?: T[K];
171-
};
170+
type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> = Pick<
171+
{ -readonly [K in keyof T]?: T[K] },
172+
OptionalPathKeys<T, TypeKey>
173+
>;
172174

173175
/**
174176
* @summary Allows users to optionally choose their own type for a schema field for stronger typing.

0 commit comments

Comments
 (0)