feat(40750): Refactoring to add inferred return type annotation to a function#41052
feat(40750): Refactoring to add inferred return type annotation to a function#41052sandersn merged 1 commit intomicrosoft:masterfrom
Conversation
65a28e8 to
570503b
Compare
sandersn
left a comment
There was a problem hiding this comment.
Looks good. I think this is a useful refactoring. There is a more general, less useful refactor that adds a type annotation on any declaration that could have one, but doesn't need to. I don't think this PR should add that (1) because it's less useful (2) I can't remember how to make a single refactoring produce multiple fixes -- it may not be possible.
@jessetrinity can you take a look too? What is your opinion on the more general refactoring?
|
@gabritto you might have opinions on the question of the more general refactoring. |
570503b to
99330a9
Compare
|
Sounds like nobody else wants to chime in, so I'll merge this after the 4.1 RC goes out. |
jessetrinity
left a comment
There was a problem hiding this comment.
Perhaps there should be some tests with multiple signatures:
// bad code - there should still be a test so that we at least know what the refactor does in this case, if doing nothing is too complicated.
function f(x: number) {
return 1;
}
function f(x: number) {
return "1";
}// good code (?) - grabbing the first signature will add "number" as the return type, but we probably wanted "number | string"
function f(x: number): number;
function f(x: string): string;
function f(x: string | number) {
return typeof(x) === "string" ? "a" : 1;
}6882451 to
e021e67
Compare
e021e67 to
44b2456
Compare
Fixes #40750