mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Add quick fix to add 'void' to Promise resolved without value (#40558)
* Add codefix to add 'void' to Promise resolved without value * Add specific error message in checker to reduce quick-fix time in editor
This commit is contained in:
@@ -26708,6 +26708,22 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isPromiseResolveArityError(node: CallLikeExpression) {
|
||||
if (!isCallExpression(node) || !isIdentifier(node.expression)) return false;
|
||||
|
||||
const symbol = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, undefined, undefined, false);
|
||||
const decl = symbol?.valueDeclaration;
|
||||
if (!decl || !isParameter(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !isNewExpression(decl.parent.parent) || !isIdentifier(decl.parent.parent.expression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const globalPromiseSymbol = getGlobalPromiseConstructorSymbol(/*reportErrors*/ false);
|
||||
if (!globalPromiseSymbol) return false;
|
||||
|
||||
const constructorSymbol = getSymbolAtLocation(decl.parent.parent.expression, /*ignoreErrors*/ true);
|
||||
return constructorSymbol === globalPromiseSymbol;
|
||||
}
|
||||
|
||||
function getArgumentArityError(node: CallLikeExpression, signatures: readonly Signature[], args: readonly Expression[]) {
|
||||
let min = Number.POSITIVE_INFINITY;
|
||||
let max = Number.NEGATIVE_INFINITY;
|
||||
@@ -26740,9 +26756,15 @@ namespace ts {
|
||||
let spanArray: NodeArray<Node>;
|
||||
let related: DiagnosticWithLocation | undefined;
|
||||
|
||||
const error = hasRestParameter || hasSpreadArgument ? hasRestParameter && hasSpreadArgument ? Diagnostics.Expected_at_least_0_arguments_but_got_1_or_more :
|
||||
hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 :
|
||||
Diagnostics.Expected_0_arguments_but_got_1_or_more : Diagnostics.Expected_0_arguments_but_got_1;
|
||||
const error = hasRestParameter || hasSpreadArgument ?
|
||||
hasRestParameter && hasSpreadArgument ?
|
||||
Diagnostics.Expected_at_least_0_arguments_but_got_1_or_more :
|
||||
hasRestParameter ?
|
||||
Diagnostics.Expected_at_least_0_arguments_but_got_1 :
|
||||
Diagnostics.Expected_0_arguments_but_got_1_or_more :
|
||||
paramRange === 1 && argCount === 0 && isPromiseResolveArityError(node) ?
|
||||
Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise :
|
||||
Diagnostics.Expected_0_arguments_but_got_1;
|
||||
|
||||
if (closestSignature && getMinArgumentCount(closestSignature) > argCount && closestSignature.declaration) {
|
||||
const paramDecl = closestSignature.declaration.parameters[closestSignature.thisParameter ? argCount + 1 : argCount];
|
||||
|
||||
@@ -3039,6 +3039,10 @@
|
||||
"category": "Error",
|
||||
"code": 2793
|
||||
},
|
||||
"Expected {0} arguments, but got {1}. Did you forget to include 'void' in your type argument to 'Promise'?": {
|
||||
"category": "Error",
|
||||
"code": 2794
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@@ -5927,6 +5931,14 @@
|
||||
"category": "Message",
|
||||
"code": 95142
|
||||
},
|
||||
"Add 'void' to Promise resolved without a value": {
|
||||
"category": "Message",
|
||||
"code": 95143
|
||||
},
|
||||
"Add 'void' to all Promises resolved without a value": {
|
||||
"category": "Message",
|
||||
"code": 95144
|
||||
},
|
||||
|
||||
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user