Skip to content

Commit f45df8f

Browse files
committed
Spelling code fix:suggestions from apparent type
The code fix for spelling correction needs to provide suggestions based on the apparent type since sometimes the type at a location will be a type parameter. One such example is `this`. Fixes #16744
1 parent c4319e3 commit f45df8f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/services/codefixes/fixSpelling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ts.codefix {
1616
const checker = context.program.getTypeChecker();
1717
let suggestion: string;
1818
if (node.kind === SyntaxKind.Identifier && isPropertyAccessExpression(node.parent)) {
19-
const containingType = checker.getTypeAtLocation(node.parent.expression);
19+
const containingType = checker.getApparentType(checker.getTypeAtLocation(node.parent.expression));
2020
suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType);
2121
}
2222
else {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////[|class C {
4+
//// state = 'hi'
5+
//// doStuff() {
6+
//// this.start;
7+
//// }
8+
////}|]
9+
10+
verify.rangeAfterCodeFix(`class C {
11+
state = 'hi'
12+
doStuff() {
13+
this.state;
14+
}
15+
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);

0 commit comments

Comments
 (0)