mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-14 07:02:44 -05:00
Improved errors for required parameters with default values in isolated declaration (#58637)
This commit is contained in:
committed by
GitHub
parent
6856735985
commit
842cf177db
@@ -32,7 +32,6 @@ import {
|
||||
isIdentifier,
|
||||
isJSDocTypeAssertion,
|
||||
isKeyword,
|
||||
isParameter,
|
||||
isPrimitiveLiteralValue,
|
||||
isShorthandPropertyAssignment,
|
||||
isSpreadAssignment,
|
||||
@@ -76,8 +75,8 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve
|
||||
serializeReturnTypeForSignature,
|
||||
serializeTypeOfExpression,
|
||||
};
|
||||
function serializeExistingTypeAnnotation(type: TypeNode | undefined) {
|
||||
return type === undefined ? undefined : !type.parent || !isParameter(type.parent) || !resolver.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type);
|
||||
function serializeExistingTypeAnnotation(type: TypeNode | undefined, addUndefined?: boolean) {
|
||||
return type !== undefined && (!addUndefined || (type && canAddUndefined(type))) ? true : undefined;
|
||||
}
|
||||
function serializeTypeOfExpression(expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) {
|
||||
return typeFromExpression(expr, context, /*isConstContext*/ false, addUndefined, preserveLiterals) ?? inferExpressionType(expr, context);
|
||||
@@ -181,12 +180,12 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve
|
||||
const declaredType = getEffectiveTypeAnnotationNode(node);
|
||||
const addUndefined = resolver.requiresAddingImplicitUndefined(node);
|
||||
let resultType;
|
||||
if (!addUndefined) {
|
||||
if (declaredType) {
|
||||
return serializeExistingTypeAnnotation(declaredType);
|
||||
}
|
||||
if (declaredType) {
|
||||
resultType = serializeExistingTypeAnnotation(declaredType, addUndefined);
|
||||
}
|
||||
else {
|
||||
if (node.initializer && isIdentifier(node.name)) {
|
||||
resultType = typeFromExpression(node.initializer, context);
|
||||
resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, addUndefined);
|
||||
}
|
||||
}
|
||||
return resultType ?? inferTypeOfDeclaration(node, context);
|
||||
|
||||
Reference in New Issue
Block a user