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

Restore existing type inference behaviour of z.ZodObject #1122

Merged
merged 2 commits into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions deno/lib/types.ts
Expand Up @@ -1363,13 +1363,18 @@ export namespace objectUtil {
[k in Exclude<keyof U, keyof V>]: U[k];
} & V;

export type requiredKeys<T extends object> = {
type optionalKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? k : never;
}[keyof T];

type requiredKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? never : k;
}[keyof T];

export type addQuestionMarks<T extends object> = {
[k in keyof T]?: T[k];
} & { [k in requiredKeys<T>]: T[k] };
export type addQuestionMarks<T extends object> = Partial<
Pick<T, optionalKeys<T>>
> &
Pick<T, requiredKeys<T>>;

export type identity<T> = T;
export type flatten<T extends object> = identity<{ [k in keyof T]: T[k] }>;
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/languageServerFeatures.test.ts
@@ -1,8 +1,9 @@
// @ts-ignore TS6133
import { expect, fit } from "@jest/globals";
import { filePath } from "./languageServerFeatures.source";
import { Project, Node, SyntaxKind } from "ts-morph";
import path from "path";
import { Node, Project, SyntaxKind } from "ts-morph";

import { filePath } from "./languageServerFeatures.source";

// The following tool is helpful for understanding the TypeScript AST associated with these tests:
// https://ts-ast-viewer.com/ (just copy the contents of languageServerFeatures.source into the viewer)
Expand Down
13 changes: 9 additions & 4 deletions src/types.ts
Expand Up @@ -1363,13 +1363,18 @@ export namespace objectUtil {
[k in Exclude<keyof U, keyof V>]: U[k];
} & V;

export type requiredKeys<T extends object> = {
type optionalKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? k : never;
}[keyof T];

type requiredKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? never : k;
}[keyof T];

export type addQuestionMarks<T extends object> = {
[k in keyof T]?: T[k];
} & { [k in requiredKeys<T>]: T[k] };
export type addQuestionMarks<T extends object> = Partial<
Pick<T, optionalKeys<T>>
> &
Pick<T, requiredKeys<T>>;

export type identity<T> = T;
export type flatten<T extends object> = identity<{ [k in keyof T]: T[k] }>;
Expand Down