mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Remove undefined when checking patterns in function declarations
This commit is contained in:
parent
739c0838e0
commit
cee708df89
@ -3098,7 +3098,8 @@ namespace ts {
|
||||
/** Return the inferred type for a binding element */
|
||||
function getTypeForBindingElement(declaration: BindingElement): Type {
|
||||
const pattern = <BindingPattern>declaration.parent;
|
||||
const parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
|
||||
let parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
|
||||
|
||||
// If parent has the unknown (error) type, then so does this binding element
|
||||
if (parentType === unknownType) {
|
||||
return unknownType;
|
||||
@ -3112,6 +3113,12 @@ namespace ts {
|
||||
}
|
||||
return parentType;
|
||||
}
|
||||
// In strict null checking mode, a default value of a binding pattern adds undefined,
|
||||
// which should be removed to get the type of the elements
|
||||
const func = getContainingFunction(declaration);
|
||||
if (strictNullChecks && func && !func.body && getFalsyFlags(parentType) & TypeFlags.Undefined) {
|
||||
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
|
||||
}
|
||||
|
||||
let type: Type;
|
||||
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
|
||||
@ -319,7 +319,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
||||
write(": ");
|
||||
if (type) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user