diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 1c807d360..64d1f8b78 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -1363,13 +1363,18 @@ export namespace objectUtil { [k in Exclude]: U[k]; } & V; - export type requiredKeys = { + type optionalKeys = { + [k in keyof T]: undefined extends T[k] ? k : never; + }[keyof T]; + + type requiredKeys = { [k in keyof T]: undefined extends T[k] ? never : k; }[keyof T]; - export type addQuestionMarks = { - [k in keyof T]?: T[k]; - } & { [k in requiredKeys]: T[k] }; + export type addQuestionMarks = Partial< + Pick> + > & + Pick>; export type identity = T; export type flatten = identity<{ [k in keyof T]: T[k] }>; diff --git a/src/__tests__/languageServerFeatures.test.ts b/src/__tests__/languageServerFeatures.test.ts index 0d065f760..5dbe9ec46 100644 --- a/src/__tests__/languageServerFeatures.test.ts +++ b/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) diff --git a/src/types.ts b/src/types.ts index 7fc741788..4600cc659 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1363,13 +1363,18 @@ export namespace objectUtil { [k in Exclude]: U[k]; } & V; - export type requiredKeys = { + type optionalKeys = { + [k in keyof T]: undefined extends T[k] ? k : never; + }[keyof T]; + + type requiredKeys = { [k in keyof T]: undefined extends T[k] ? never : k; }[keyof T]; - export type addQuestionMarks = { - [k in keyof T]?: T[k]; - } & { [k in requiredKeys]: T[k] }; + export type addQuestionMarks = Partial< + Pick> + > & + Pick>; export type identity = T; export type flatten = identity<{ [k in keyof T]: T[k] }>;