Skip to content

Commit ceb50b6

Browse files
author
Andy Hanson
committed
Add test for #21317
1 parent a3387cc commit ceb50b6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/harness/fourslash.ts

+12
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,14 @@ namespace FourSlash {
880880
});
881881
}
882882

883+
public verifyTypeAtLocation(markerName: string, type: string) {
884+
const marker = this.getMarkerByName(markerName);
885+
const file = this.getProgram().getSourceFile(marker.fileName)!;
886+
const node = ts.findPrecedingToken(marker.position, file);
887+
const checker = this.getProgram().getTypeChecker();
888+
assert.equal(checker.typeToString(checker.getTypeAtLocation(node)), type);
889+
}
890+
883891
public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string | { kind?: string, kindModifiers?: string }, spanIndex?: number, hasAction?: boolean, options?: FourSlashInterface.VerifyCompletionListContainsOptions) {
884892
const completions = this.getCompletionListAtCaret(options);
885893
if (completions) {
@@ -3989,6 +3997,10 @@ namespace FourSlashInterface {
39893997
super(state);
39903998
}
39913999

4000+
public typeAtLocation(markerName: string, type: string) {
4001+
this.state.verifyTypeAtLocation(markerName, type);
4002+
}
4003+
39924004
public completionsAt(markerName: string, completions: ReadonlyArray<ExpectedCompletionEntry>, options?: CompletionsAtOptions) {
39934005
this.state.verifyCompletionsAt(markerName, completions, options);
39944006
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strictNullChecks: true
4+
5+
////function test<T extends string | undefined>(x: T) {
6+
//// x/**/!;
7+
////}
8+
9+
verify.typeAtLocation("", "string | undefined"); // TODO: GH#21317: should be "T".

0 commit comments

Comments
 (0)