Skip to content

Commit fe55edc

Browse files
committed
Rest in an untyped binding pattern should be any
1 parent e313fef commit fe55edc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,15 @@ namespace ts {
30993099
error(declaration, Diagnostics.Rest_types_may_only_be_created_from_object_types);
31003100
return unknownType;
31013101
}
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+
}
31023111
const literalMembers: PropertyName[] = [];
31033112
for (const element of pattern.elements) {
31043113
if (!(element as BindingElement).dotDotDotToken) {

0 commit comments

Comments
 (0)