Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correct propagation of includePatternInType flag
  • Loading branch information
ahejlsberg committed Sep 6, 2015
commit 546da60a2a9321d50856e28c10bee8be3264c0e2
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,12 +2416,12 @@ namespace ts {
// Return the type implied by a binding pattern element. This is the type of the initializer of the element if
// one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element: BindingElement): Type {
function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean): Type {
if (element.initializer) {
return getWidenedType(checkExpressionCached(element.initializer));
}
if (isBindingPattern(element.name)) {
return getTypeFromBindingPattern(<BindingPattern>element.name, /*includePatternInType*/ false);
return getTypeFromBindingPattern(<BindingPattern>element.name, includePatternInType);
}
return anyType;
}
Expand All @@ -2433,7 +2433,7 @@ namespace ts {
let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
let name = e.propertyName || <Identifier>e.name;
let symbol = <TransientSymbol>createSymbol(flags, name.text);
symbol.type = getTypeFromBindingElement(e);
symbol.type = getTypeFromBindingElement(e, includePatternInType);
members[symbol.name] = symbol;
});
let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
Expand All @@ -2450,7 +2450,7 @@ namespace ts {
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
}
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e));
let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType));
let result = createTupleType(elementTypes);
if (includePatternInType) {
result = clone(result);
Expand Down