Skip to content

Commit e9453f4

Browse files
authored
fix(47524): skip assertion on checking this in fixImplicitThis QF (#47527)
1 parent ab4d319 commit e9453f4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/services/codefixes/fixImplicitThis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ts.codefix {
44
const errorCodes = [Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation.code];
55
registerCodeFix({
66
errorCodes,
7-
getCodeActions(context) {
7+
getCodeActions: function getCodeActionsToFixImplicitThis(context) {
88
const { sourceFile, program, span } = context;
99
let diagnostic: DiagnosticAndArguments | undefined;
1010
const changes = textChanges.ChangeTracker.with(context, t => {
@@ -20,7 +20,7 @@ namespace ts.codefix {
2020

2121
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, checker: TypeChecker): DiagnosticAndArguments | undefined {
2222
const token = getTokenAtPosition(sourceFile, pos);
23-
Debug.assert(token.kind === SyntaxKind.ThisKeyword);
23+
if (!isThis(token)) return undefined;
2424

2525
const fn = getThisContainer(token, /*includeArrowFunctions*/ false);
2626
if (!isFunctionDeclaration(fn) && !isFunctionExpression(fn)) return undefined;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitThis: true
4+
5+
////function foo() {
6+
//// let x: typeof /**/this;
7+
////}
8+
9+
verify.codeFixAvailable([
10+
{ description: "Infer 'this' type of 'foo' from usage" },
11+
{ description: "Remove unused declaration for: 'x'" }
12+
]);

0 commit comments

Comments
 (0)