Skip to content

Commit 8a66d15

Browse files
committed
refactor: Reword void Promise message for JSDoc type hint to provide better feedback
1 parent 47998e5 commit 8a66d15

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30413,11 +30413,15 @@ namespace ts {
3041330413
const parameterRange = hasRestParameter ? min
3041430414
: min < max ? min + "-" + max
3041530415
: min;
30416-
const error = hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1
30417-
: parameterRange === 1 && args.length === 0 && isPromiseResolveArityError(node) ? isInJSFile(node)
30418-
? Diagnostics.Expected_0_arguments_but_got_1_TypeScript_may_need_a_JSDoc_hint_that_the_call_to_new_Promise_produces_a_Promise_void
30419-
: Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise
30420-
: Diagnostics.Expected_0_arguments_but_got_1;
30416+
const isVoidPromiseError = !hasRestParameter && parameterRange === 1 && args.length === 0 && isPromiseResolveArityError(node);
30417+
if (isVoidPromiseError && isInJSFile(node)) {
30418+
return getDiagnosticForCallNode(node, Diagnostics.Expected_1_argument_but_got_0_new_Promise_need_a_JSDoc_hint_to_produce_a_0_that_can_be_called_without_arguments, "resolve");
30419+
}
30420+
const error = hasRestParameter
30421+
? Diagnostics.Expected_at_least_0_arguments_but_got_1
30422+
: isVoidPromiseError
30423+
? Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise
30424+
: Diagnostics.Expected_0_arguments_but_got_1;
3042130425
if (min < args.length && args.length < max) {
3042230426
// between min and max, but with no matching overload
3042330427
return getDiagnosticForCallNode(node, Diagnostics.No_overload_expects_0_arguments_but_overloads_do_exist_that_expect_either_1_or_2_arguments, args.length, maxBelow, minAbove);

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3369,7 +3369,7 @@
33693369
"category": "Error",
33703370
"code": 2809
33713371
},
3372-
"Expected {0} arguments, but got {1}. TypeScript may need a JSDoc hint that the call to 'new Promise()' produces a 'Promise<void>'": {
3372+
"Expected 1 argument, but got 0. 'new Promise()' need a JSDoc hint to produce a {0} that can be called without arguments.": {
33733373
"category": "Error",
33743374
"code": 2810
33753375
},

src/services/codefixes/fixAddVoidToPromise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace ts.codefix {
33
const fixName = "addVoidToPromise";
44
const fixId = "addVoidToPromise";
55
const errorCodes = [
6-
Diagnostics.Expected_0_arguments_but_got_1_TypeScript_may_need_a_JSDoc_hint_that_the_call_to_new_Promise_produces_a_Promise_void.code,
6+
Diagnostics.Expected_1_argument_but_got_0_new_Promise_need_a_JSDoc_hint_to_produce_a_0_that_can_be_called_without_arguments.code,
77
Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise.code
88
];
99
registerCodeFix({

0 commit comments

Comments
 (0)