@@ -3099,15 +3099,6 @@ namespace ts {
3099
3099
error(declaration, Diagnostics.Rest_types_may_only_be_created_from_object_types);
3100
3100
return unknownType;
3101
3101
}
3102
- const parent = pattern.parent as VariableLikeDeclaration;
3103
- if (parent.kind === SyntaxKind.Parameter &&
3104
- !parent.type &&
3105
- !parent.initializer &&
3106
- !getContextuallyTypedParameterType(parent as ParameterDeclaration)) {
3107
- // if this type came from examining the structure of the pattern --
3108
- // there was no other information -- then it is not sufficient to determine the rest type, so just return any
3109
- return anyType;
3110
- }
3111
3102
const literalMembers: PropertyName[] = [];
3112
3103
for (const element of pattern.elements) {
3113
3104
if (!(element as BindingElement).dotDotDotToken) {
@@ -3318,14 +3309,19 @@ namespace ts {
3318
3309
// Return the type implied by an object binding pattern
3319
3310
function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
3320
3311
const members = createMap<Symbol>();
3312
+ let stringIndexInfo: IndexInfo;
3321
3313
let hasComputedProperties = false;
3322
3314
forEach(pattern.elements, e => {
3323
3315
const name = e.propertyName || <Identifier>e.name;
3324
- if (isComputedNonLiteralName(name) || e.dotDotDotToken ) {
3325
- // do not include computed properties or rests in the implied type
3316
+ if (isComputedNonLiteralName(name)) {
3317
+ // do not include computed properties in the implied type
3326
3318
hasComputedProperties = true;
3327
3319
return;
3328
3320
}
3321
+ if (e.dotDotDotToken) {
3322
+ stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
3323
+ return;
3324
+ }
3329
3325
3330
3326
const text = getTextOfPropertyName(name);
3331
3327
const flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
@@ -3334,7 +3330,7 @@ namespace ts {
3334
3330
symbol.bindingElement = e;
3335
3331
members[symbol.name] = symbol;
3336
3332
});
3337
- const result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined , undefined);
3333
+ const result = createAnonymousType(undefined, members, emptyArray, emptyArray, stringIndexInfo , undefined);
3338
3334
if (includePatternInType) {
3339
3335
result.pattern = pattern;
3340
3336
}
@@ -11422,7 +11418,8 @@ namespace ts {
11422
11418
if (impliedProp) {
11423
11419
prop.flags |= impliedProp.flags & SymbolFlags.Optional;
11424
11420
}
11425
- else if (!compilerOptions.suppressExcessPropertyErrors) {
11421
+
11422
+ else if (!compilerOptions.suppressExcessPropertyErrors && !getIndexInfoOfType(contextualType, IndexKind.String)) {
11426
11423
error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
11427
11424
symbolToString(member), typeToString(contextualType));
11428
11425
}
0 commit comments