diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index e4e30e67cec..5b00a2a7482 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2923,6 +2923,10 @@ Actual: ${stringify(fullActual)}`); if (!codeFixes.length) { this.raiseError(`verifyCodeFixAvailable failed - expected code fixes but none found.`); } + codeFixes.forEach(fix => fix.changes.forEach(change => { + assert.isObject(change, `Invalid change in code fix: ${JSON.stringify(fix)}`); + change.textChanges.forEach(textChange => assert.isObject(textChange, `Invalid textChange in codeFix: ${JSON.stringify(fix)}`)); + })); if (info) { assert.equal(info.length, codeFixes.length); ts.zipWith(codeFixes, info, (fix, info) => { diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index b5a9e15f5a4..18df488e979 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -186,7 +186,8 @@ namespace ts.codefix { } function makeFix(declaration: Declaration, start: number, type: Type | undefined, program: Program): Fix | undefined { - return type && { declaration, textChanges: [makeChange(declaration, start, type, program)] }; + const change = makeChange(declaration, start, type, program); + return change && { declaration, textChanges: [change] }; } function makeChange(declaration: Declaration, start: number, type: Type | undefined, program: Program): TextChange | undefined { diff --git a/tests/cases/fourslash/codeFixInferFromUsageSetterWithInaccessibleType.ts b/tests/cases/fourslash/codeFixInferFromUsageSetterWithInaccessibleType.ts new file mode 100644 index 00000000000..96c76a64837 --- /dev/null +++ b/tests/cases/fourslash/codeFixInferFromUsageSetterWithInaccessibleType.ts @@ -0,0 +1,16 @@ +/// + +// @noImplicitAny: true + +// @Filename: /a.ts +////export class D {} +////export default new D(); + +// @Filename: /b.ts +////export class C { +//// [|set x(val) {}|] +//// method() { this.x = import("./a"); } +////} + +goTo.file("/b.ts"); +verify.not.codeFixAvailable(); \ No newline at end of file