From a2cefc5d9d44c40f903d9539299c75e5e66279a4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 9 Aug 2021 18:04:21 -0700 Subject: [PATCH 1/2] Some cleanup around inlay hints types to get more-precise checking. --- src/harness/client.ts | 2 +- src/server/protocol.ts | 8 ++------ src/server/session.ts | 2 +- src/services/types.ts | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index c72cfe681a725..aa40bcdb55f3f 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -653,7 +653,7 @@ namespace ts.server { return response.body!.map(item => ({ // TODO: GH#18217 ...item, - kind: item.kind as InlayHintKind | undefined, + kind: item.kind as InlayHintKind, position: this.lineOffsetToPosition(file, item.position), })); } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 661639479aafa..6147077051b52 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2562,11 +2562,7 @@ namespace ts.server.protocol { body?: SignatureHelpItems; } - export const enum InlayHintKind { - Type = "Type", - Parameter = "Parameter", - Enum = "Enum", - } + export type InlayHintKind = "Type" | "Parameter" | "Enum"; export interface InlayHintsRequestArgs extends FileRequestArgs { /** @@ -2587,7 +2583,7 @@ namespace ts.server.protocol { export interface InlayHintItem { text: string; position: Location; - kind?: InlayHintKind; + kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/src/server/session.ts b/src/server/session.ts index f08d809a171d3..6ab9500db2352 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1452,7 +1452,7 @@ namespace ts.server { }); } - private provideInlayHints(args: protocol.InlayHintsRequestArgs) { + private provideInlayHints(args: protocol.InlayHintsRequestArgs): readonly protocol.InlayHintItem[] { const { file, project } = this.getFileAndProject(args); const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; const hints = project.getLanguageService().provideInlayHints(file, args, this.getPreferences(file)); diff --git a/src/services/types.ts b/src/services/types.ts index 4ad9ddfa88946..0e5d95a15e971 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -720,7 +720,7 @@ namespace ts { export interface InlayHint { text: string; position: number; - kind?: InlayHintKind; + kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } From 90a14ee36273c2a0cd4443c339ec5d78193f73dd Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 23 Aug 2021 20:34:34 +0000 Subject: [PATCH 2/2] Update Baselines and/or Applied Lint Fixes --- tests/baselines/reference/api/tsserverlibrary.d.ts | 10 +++------- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 803d3163ef209..add6513cf79e4 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5886,7 +5886,7 @@ declare namespace ts { interface InlayHint { text: string; position: number; - kind?: InlayHintKind; + kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } @@ -8739,11 +8739,7 @@ declare namespace ts.server.protocol { interface SignatureHelpResponse extends Response { body?: SignatureHelpItems; } - enum InlayHintKind { - Type = "Type", - Parameter = "Parameter", - Enum = "Enum" - } + type InlayHintKind = "Type" | "Parameter" | "Enum"; interface InlayHintsRequestArgs extends FileRequestArgs { /** * Start position of the span. @@ -8761,7 +8757,7 @@ declare namespace ts.server.protocol { interface InlayHintItem { text: string; position: Location; - kind?: InlayHintKind; + kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 94d77a0c42dd1..31f5453c3f3b3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5886,7 +5886,7 @@ declare namespace ts { interface InlayHint { text: string; position: number; - kind?: InlayHintKind; + kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; }