Add refactoring action to annotate a variable or a function signature component with its inferred type
See original GitHub issueHi, I’m using latest stable VSCode / latest nightly TS and I’m not sure if codefixes and refactorings have been implemented there yet, in any case, having a refactoring option to take any variable which receives an implicit inferred type, say, through a function call:
function test(): number[] {
// ...
}
let x = test();
And being able to right-click x
and invoke an action like Annotate with inferred type
(or Extract inferred type
), such that the resulting statement would look like:
let x: number[] = test();
could be very useful!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:17
- Comments:15 (6 by maintainers)
Top Results From Across the Web
The Infer function return type refactoring for TypeScript
Today's VS Code tip: Infer function return typeUse this refactoring to quickly add explicit type annotations to functions /methods in ...
Read more >TypeScript refactoring with Visual Studio Code
Visual Studio Code has built-in support for TypeScript refactoring through the TypeScript language ... The Infer function return type refactoring in action.
Read more >My experience with Typescript annotations - Medium
Typescript allows you to add types to JavaScript files using ... just assert the type of that variable and rest is inferred correctly....
Read more >1. Typechecking - Hack and HHVM [Book] - O'Reilly
To enhance the typechecker's ability to do this, Hack allows programmers to explicitly annotate the types of some values in their programs: function...
Read more >Refactoring Java Generics by Inferring Wildcards, In Practice
Wildcard annotations can improve the generality of Java generic libraries, but require heavy ... The type signature of List.add contains the type parameter....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would certainly appreciate having the opposite capability.
Also, being able to annotate functions or methods with their inferred return types, e.g.
Right click
test
, selectAnnotate with inferred return type
, leading to:Would also be very useful. I do that a lot, sometimes to have it visibly documented, or make sure that the return type is stabilized such that further changes to the body of the function that break it would be detected.
There are also cases where callback’s signature types are inferred like
Where right clicking
x
,y
or=>
and choosingAnnotate with inferred type
/Annotate with inferred return type
or even combined to a single action likeAnnotate with inferred signature
(maybe when, say, the arrow is right clicked for an anonymous function) could also be useful.