Mark implied object destructuring patterns as object literal types

This commit is contained in:
Anders Hejlsberg committed 2018-03-17 12:02:19 -07:00
1 parent bb23e9601f
commit 20c008ecab
1 file changed
+4 -5
+4 -5
View File
@@ -4310,12 +4310,12 @@ namespace ts {
function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
const members = createSymbolTable();
let stringIndexInfo: IndexInfo;
let hasComputedProperties = false;
let objectFlags = ObjectFlags.ObjectLiteral;
forEach(pattern.elements, e => {
const name = e.propertyName || <Identifier>e.name;
if (isComputedNonLiteralName(name)) {
// do not include computed properties in the implied type
hasComputedProperties = true;
objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties;
return;
}
if (e.dotDotDotToken) {
@@ -4331,12 +4331,11 @@ namespace ts {
members.set(symbol.escapedName, symbol);
});
const result = createAnonymousType(undefined, members, emptyArray, emptyArray, stringIndexInfo, undefined);
result.flags |= TypeFlags.ContainsObjectLiteral;
result.objectFlags |= objectFlags;
if (includePatternInType) {
result.pattern = pattern;
}
if (hasComputedProperties) {
result.objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties;
}
return result;
}