Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: improve goto definition for inferred schema definitions #14968

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ type RequiredPathKeys<T, TypeKey extends string = DefaultTypeKey> = {
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
* @returns a record contains required paths with the corresponding type.
*/
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> = {
[K in RequiredPathKeys<T, TypeKey>]: T[K];
};
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> = Pick<
{ -readonly [K in keyof T]: T[K] },
RequiredPathKeys<T, TypeKey>
>;

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

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