fix(47524): skip assertion on checking this in fixImplicitThis QF (#47527)

This commit is contained in:
Oleksandr T
2022-01-21 00:58:28 +02:00
committed by GitHub
parent ab4d3198ed
commit e9453f411a
2 changed files with 14 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ namespace ts.codefix {
const errorCodes = [Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation.code];
registerCodeFix({
errorCodes,
getCodeActions(context) {
getCodeActions: function getCodeActionsToFixImplicitThis(context) {
const { sourceFile, program, span } = context;
let diagnostic: DiagnosticAndArguments | undefined;
const changes = textChanges.ChangeTracker.with(context, t => {
@@ -20,7 +20,7 @@ namespace ts.codefix {
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, checker: TypeChecker): DiagnosticAndArguments | undefined {
const token = getTokenAtPosition(sourceFile, pos);
Debug.assert(token.kind === SyntaxKind.ThisKeyword);
if (!isThis(token)) return undefined;
const fn = getThisContainer(token, /*includeArrowFunctions*/ false);
if (!isFunctionDeclaration(fn) && !isFunctionExpression(fn)) return undefined;

View File

@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
// @noImplicitThis: true
////function foo() {
//// let x: typeof /**/this;
////}
verify.codeFixAvailable([
{ description: "Infer 'this' type of 'foo' from usage" },
{ description: "Remove unused declaration for: 'x'" }
]);