From 80ab138037a79ba8267e8c7f5af150fe4850d3d6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 21 Aug 2021 01:06:19 +0000 Subject: [PATCH] Cherry-pick PR #45391 into release-4.4 Component commits: a2cefc5d9d 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; }