Search Terms
extract constant refactoring expression arrow type parameter argument
Suggestion
Given:
If you highlight x => x + 1 then run "extract to constant", you'll get:
const newLocal: (value: number, index: number, array: number[]) => number = x => x + 1;
[1,2,3].map(newLocal)
I can understand why this might make sense in some cases, but 99% of the time (in my experience), I end up having to tediously alter the constant that TypeScript has created for me. What I actually want is:
const newLocal = (x: number): number => x + 1;
[1,2,3].map(newLocal)
- I want my parameter and return types to be inlined in the definition
- (Less important.) I only care about the parameters that are in use
Perhaps this suggested behaviour could be a setting for the existing refactoring, or another refactoring entirely, or a new/better default for this existing refactoring.
Another example:
[1,2,3].map((x): number => x + 1)
produces
const newLocal: (value: number, index: number, array: number[]) => number = (x): number => x + 1;
[1,2,3].map(newLocal)
The return type is duplicated: it appears both inline and in the constant annotation.
Checklist
My suggestion meets these guidelines:
Search Terms
extract constant refactoring expression arrow type parameter argument
Suggestion
Given:
If you highlight
x => x + 1then run "extract to constant", you'll get:I can understand why this might make sense in some cases, but 99% of the time (in my experience), I end up having to tediously alter the constant that TypeScript has created for me. What I actually want is:
Perhaps this suggested behaviour could be a setting for the existing refactoring, or another refactoring entirely, or a new/better default for this existing refactoring.
Another example:
produces
The return type is duplicated: it appears both inline and in the constant annotation.
Checklist
My suggestion meets these guidelines: