question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a refactoring that annotates an implicit or explicit any with a best guess type inferred from its use sites

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
mhegazycommented, Apr 21, 2017
2reactions
zpdDG4gta8XKpMCdcommented, Jan 2, 2017

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

// before
function log(value: any) {
}
log(1);
log('a');
// after code action
log(value: number | string) {
}
log(1);
log('a');
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found