Add a refactoring that annotates an implicit or explicit any with a best guess type inferred from its use sites
See original GitHub issueI would very much appreciate having a codefix (refactoring) that, given an explicit any
annotation, offers to change it to an {}
annotation.
For example, given
function log(x: any) {
console.log(x);
}
a code fix would be offered to change the declared type of x
to {}
resulting in
function log(x: {}) {
console.log(x);
}
However, given
function log(x: any) {
console.log(x.name);
}
a code fix would be offered to change the declared type of x
to { name: any }
resulting in
function log(x: {name: any}) {
console.log(x);
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
TypeScript - how to work with implicit and explicit types?
Entering the world of TypeScript gives you multiple paths to follow. In this article I compare explicit and implicit type annotations.
Read more >implicitly has return type 'any' because it does not have a return type ...
implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of...
Read more >Weblogs Forum - Is Static Typing a Form of Bad Coupling?
A worthy goal, but why not simply move to implicit typing. A type can be inferred from context, as in the example you...
Read more >Data Types - The Rust Programming Language
We'll look at two data type subsets: scalar and compound. Keep in mind that Rust is a statically typed language, which means that...
Read more >Custom pluggable types for ... - The Checker Framework Manual
The Nullness Checker adds implicit qualifiers, reducing the number of ... at all client uses, even the places that you want to check....
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
Addressed by https://github.com/Microsoft/TypeScript/pull/14786
i gave it a second thought, i might be helpful if such code action looked for all places that call this function and tried to deduce the replacement type out of all possible arguments out there