TypeScript/tests/cases/fourslash/extract-const-callback-function-this2.ts
Titian Cernicova-Dragomir 232ee608d5 Improved const extraction for function expressions and arrow functions. The behavior applies if the function:
- is contextually typed (because otherwise no type annotation for the variable would have been generated anyway)
- is not generic
- doesn't have parameters inferred as any

If these conditions are met, we add missing parameters type and we add this parameter to the function.
2019-07-11 14:38:59 +03:00

16 lines
587 B
TypeScript

/// <reference path='fourslash.ts' />
////declare function fWithThis(fn: (this: { a: string }, a: string) => string): void;
////fWithThis(/*a*/function (a) { return this.a; }/*b*/);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Extract Symbol",
actionName: "constant_scope_0",
actionDescription: "Extract to constant in enclosing scope",
newContent:
`declare function fWithThis(fn: (this: { a: string }, a: string) => string): void;
const newLocal = function(this: { a: string; }, a: string): string { return this.a; };
fWithThis(/*RENAME*/newLocal);`
});