File tree Expand file tree Collapse file tree 5 files changed +48
-1
lines changed Expand file tree Collapse file tree 5 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -27083,6 +27083,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27083
27083
}
27084
27084
27085
27085
function getNarrowedTypeOfSymbol(symbol: Symbol, location: Identifier) {
27086
+ const type = getTypeOfSymbol(symbol);
27086
27087
const declaration = symbol.valueDeclaration;
27087
27088
if (declaration) {
27088
27089
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
@@ -27163,7 +27164,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27163
27164
}
27164
27165
}
27165
27166
}
27166
- return getTypeOfSymbol(symbol) ;
27167
+ return type ;
27167
27168
}
27168
27169
27169
27170
function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type {
Original file line number Diff line number Diff line change @@ -1144,6 +1144,17 @@ export class TestState {
1144
1144
}
1145
1145
}
1146
1146
1147
+ public verifyTypeAtLocation ( range : Range , expected : string ) : void {
1148
+ const node = this . goToAndGetNode ( range ) ;
1149
+ const checker = this . getChecker ( ) ;
1150
+ const type = checker . getTypeAtLocation ( node ) ;
1151
+
1152
+ const actual = checker . typeToString ( type ) ;
1153
+ if ( actual !== expected ) {
1154
+ this . raiseError ( displayExpectedAndActualString ( expected , actual ) ) ;
1155
+ }
1156
+ }
1157
+
1147
1158
public verifyBaselineFindAllReferences ( ...markerNames : string [ ] ) {
1148
1159
ts . Debug . assert ( markerNames . length > 0 , "Must pass at least one marker name to `verifyBaselineFindAllReferences()`" ) ;
1149
1160
this . verifyBaselineFindAllReferencesWorker ( "" , markerNames ) ;
Original file line number Diff line number Diff line change @@ -354,6 +354,10 @@ export class Verify extends VerifyNegatable {
354
354
this . state . verifyTypeOfSymbolAtLocation ( range , symbol , expected ) ;
355
355
}
356
356
357
+ public typeAtLocation ( range : FourSlash . Range , expected : string ) {
358
+ this . state . verifyTypeAtLocation ( range , expected ) ;
359
+ }
360
+
357
361
public baselineFindAllReferences ( ...markerNames : string [ ] ) {
358
362
this . state . verifyBaselineFindAllReferences ( ...markerNames ) ;
359
363
}
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ // Issue #48313
4
+
5
+ // @strict : true
6
+ // @target : esnext
7
+ // @Filename : /file.tsx
8
+ //// export function working(baseVersion?: string): number[] {
9
+ //// const toRelease: number[] = [];
10
+ //// const baseRelease: number[] = [];
11
+ //// return baseRelease.map((_, index) => {
12
+ //// const toPart = toRelease[index] ?? 0;
13
+ //// [|toPart|]; // this is the "working" log
14
+ //// return 0;
15
+ //// });
16
+ //// }
17
+ ////
18
+ //// export function broken(baseVersion?: string): number[] {
19
+ //// const toRelease: number[] = [];
20
+ //// const baseRelease: number[] = [];
21
+ //// return baseRelease.map((_, index) => {
22
+ //// const toPart = toRelease[index] ?? 0;
23
+ //// [|toPart|]; // this is the "broken" log
24
+ //// return toPart + (baseVersion === undefined ? 0 : 1);
25
+ //// });
26
+ //// }
27
+
28
+ const [ r_ok , r_bad ] = test . ranges ( ) ;
29
+ verify . typeAtLocation ( r_ok , "number" ) ;
30
+ verify . typeAtLocation ( r_bad , "number" ) ;
Original file line number Diff line number Diff line change @@ -335,6 +335,7 @@ declare namespace FourSlashInterface {
335
335
baselineGetFileReferences ( fileName : string ) : void ;
336
336
symbolAtLocation ( startRange : Range , ...declarationRanges : Range [ ] ) : void ;
337
337
typeOfSymbolAtLocation ( range : Range , symbol : any , expected : string ) : void ;
338
+ typeAtLocation ( range : Range , expected : string ) : void ;
338
339
/** @deprecated Use baselineFindAllReferences instead */
339
340
singleReferenceGroup ( definition : ReferencesDefinition , ranges ?: Range [ ] | string ) : void ;
340
341
rangesAreOccurrences ( isWriteAccess ?: boolean , ranges ?: Range [ ] ) : void ;
You can’t perform that action at this time.
0 commit comments