mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 12:57:11 -06:00
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
This commit is contained in:
parent
c4319e3b94
commit
f45df8fb69
@ -16,7 +16,7 @@ namespace ts.codefix {
|
||||
const checker = context.program.getTypeChecker();
|
||||
let suggestion: string;
|
||||
if (node.kind === SyntaxKind.Identifier && isPropertyAccessExpression(node.parent)) {
|
||||
const containingType = checker.getTypeAtLocation(node.parent.expression);
|
||||
const containingType = checker.getApparentType(checker.getTypeAtLocation(node.parent.expression));
|
||||
suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType);
|
||||
}
|
||||
else {
|
||||
|
||||
15
tests/cases/fourslash/codeFixCorrectSpelling.ts
Normal file
15
tests/cases/fourslash/codeFixCorrectSpelling.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|class C {
|
||||
//// state = 'hi'
|
||||
//// doStuff() {
|
||||
//// this.start;
|
||||
//// }
|
||||
////}|]
|
||||
|
||||
verify.rangeAfterCodeFix(`class C {
|
||||
state = 'hi'
|
||||
doStuff() {
|
||||
this.state;
|
||||
}
|
||||
}`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);
|
||||
Loading…
x
Reference in New Issue
Block a user