Skip to content

Commit af54990

Browse files
Some cleanup around inlay hints types to get more-precise checking. (microsoft#45391)
* Some cleanup around inlay hints types to get more-precise checking. * Update Baselines and/or Applied Lint Fixes Co-authored-by: TypeScript Bot <[email protected]>
1 parent b8ace9d commit af54990

File tree

6 files changed

+9
-17
lines changed

6 files changed

+9
-17
lines changed

src/harness/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ namespace ts.server {
653653

654654
return response.body!.map(item => ({ // TODO: GH#18217
655655
...item,
656-
kind: item.kind as InlayHintKind | undefined,
656+
kind: item.kind as InlayHintKind,
657657
position: this.lineOffsetToPosition(file, item.position),
658658
}));
659659
}

src/server/protocol.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -2562,11 +2562,7 @@ namespace ts.server.protocol {
25622562
body?: SignatureHelpItems;
25632563
}
25642564

2565-
export const enum InlayHintKind {
2566-
Type = "Type",
2567-
Parameter = "Parameter",
2568-
Enum = "Enum",
2569-
}
2565+
export type InlayHintKind = "Type" | "Parameter" | "Enum";
25702566

25712567
export interface InlayHintsRequestArgs extends FileRequestArgs {
25722568
/**
@@ -2587,7 +2583,7 @@ namespace ts.server.protocol {
25872583
export interface InlayHintItem {
25882584
text: string;
25892585
position: Location;
2590-
kind?: InlayHintKind;
2586+
kind: InlayHintKind;
25912587
whitespaceBefore?: boolean;
25922588
whitespaceAfter?: boolean;
25932589
}

src/server/session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ namespace ts.server {
14521452
});
14531453
}
14541454

1455-
private provideInlayHints(args: protocol.InlayHintsRequestArgs) {
1455+
private provideInlayHints(args: protocol.InlayHintsRequestArgs): readonly protocol.InlayHintItem[] {
14561456
const { file, project } = this.getFileAndProject(args);
14571457
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
14581458
const hints = project.getLanguageService().provideInlayHints(file, args, this.getPreferences(file));

src/services/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ namespace ts {
720720
export interface InlayHint {
721721
text: string;
722722
position: number;
723-
kind?: InlayHintKind;
723+
kind: InlayHintKind;
724724
whitespaceBefore?: boolean;
725725
whitespaceAfter?: boolean;
726726
}

tests/baselines/reference/api/tsserverlibrary.d.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -5887,7 +5887,7 @@ declare namespace ts {
58875887
interface InlayHint {
58885888
text: string;
58895889
position: number;
5890-
kind?: InlayHintKind;
5890+
kind: InlayHintKind;
58915891
whitespaceBefore?: boolean;
58925892
whitespaceAfter?: boolean;
58935893
}
@@ -8740,11 +8740,7 @@ declare namespace ts.server.protocol {
87408740
interface SignatureHelpResponse extends Response {
87418741
body?: SignatureHelpItems;
87428742
}
8743-
enum InlayHintKind {
8744-
Type = "Type",
8745-
Parameter = "Parameter",
8746-
Enum = "Enum"
8747-
}
8743+
type InlayHintKind = "Type" | "Parameter" | "Enum";
87488744
interface InlayHintsRequestArgs extends FileRequestArgs {
87498745
/**
87508746
* Start position of the span.
@@ -8762,7 +8758,7 @@ declare namespace ts.server.protocol {
87628758
interface InlayHintItem {
87638759
text: string;
87648760
position: Location;
8765-
kind?: InlayHintKind;
8761+
kind: InlayHintKind;
87668762
whitespaceBefore?: boolean;
87678763
whitespaceAfter?: boolean;
87688764
}

tests/baselines/reference/api/typescript.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5887,7 +5887,7 @@ declare namespace ts {
58875887
interface InlayHint {
58885888
text: string;
58895889
position: number;
5890-
kind?: InlayHintKind;
5890+
kind: InlayHintKind;
58915891
whitespaceBefore?: boolean;
58925892
whitespaceAfter?: boolean;
58935893
}

0 commit comments

Comments
 (0)