diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e6970df6811fc..6815b2c352d7f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3606,6 +3606,8 @@ namespace ts { case SyntaxKind.TypeLiteral: case SyntaxKind.ArrayType: case SyntaxKind.TupleType: + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: case SyntaxKind.UnionType: case SyntaxKind.IntersectionType: case SyntaxKind.ConditionalType: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57e34d86080a7..1e94126722f55 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -354,7 +354,7 @@ namespace ts { } }; - const tupleTypes: GenericType[] = []; + const tupleTypes = createMap(); const unionTypes = createMap(); const intersectionTypes = createMap(); const literalTypes = createMap(); @@ -3370,8 +3370,15 @@ namespace ts { } else if (type.target.objectFlags & ObjectFlags.Tuple) { if (typeArguments.length > 0) { - const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, getTypeReferenceArity(type)), context); + const arity = getTypeReferenceArity(type); + const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, arity), context); + const hasRestElement = (type.target).hasRestElement; if (tupleConstituentNodes && tupleConstituentNodes.length > 0) { + for (let i = (type.target).minLength; i < arity; i++) { + tupleConstituentNodes[i] = hasRestElement && i === arity - 1 ? + createRestTypeNode(createArrayTypeNode(tupleConstituentNodes[i])) : + createOptionalTypeNode(tupleConstituentNodes[i]); + } return createTupleTypeNode(tupleConstituentNodes); } } @@ -3601,7 +3608,7 @@ namespace ts { typeParameters = signature.typeParameters && signature.typeParameters.map(parameter => typeParameterToDeclaration(parameter, context)); } - const parameters = signature.parameters.map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor)); + const parameters = getExpandedParameters(signature).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor)); if (signature.thisParameter) { const thisParameter = symbolToParameterDeclaration(signature.thisParameter, context); parameters.unshift(thisParameter); @@ -3670,7 +3677,7 @@ namespace ts { const parameterTypeNode = typeToTypeNodeHelper(parameterType, context); const modifiers = !(context.flags & NodeBuilderFlags.OmitParameterModifiers) && preserveModifierFlags && parameterDeclaration && parameterDeclaration.modifiers ? parameterDeclaration.modifiers.map(getSynthesizedClone) : undefined; - const isRest = parameterDeclaration ? isRestParameter(parameterDeclaration) : (parameterSymbol as TransientSymbol).isRestParameter; + const isRest = parameterDeclaration && isRestParameter(parameterDeclaration) || getCheckFlags(parameterSymbol) & CheckFlags.RestParameter; const dotDotDotToken = isRest ? createToken(SyntaxKind.DotDotDotToken) : undefined; const name = parameterDeclaration ? parameterDeclaration.name ? @@ -3679,7 +3686,8 @@ namespace ts { cloneBindingName(parameterDeclaration.name) : symbolName(parameterSymbol) : symbolName(parameterSymbol); - const questionToken = parameterDeclaration && isOptionalParameter(parameterDeclaration) ? createToken(SyntaxKind.QuestionToken) : undefined; + const isOptional = parameterDeclaration && isOptionalParameter(parameterDeclaration) || getCheckFlags(parameterSymbol) & CheckFlags.OptionalParameter; + const questionToken = isOptional ? createToken(SyntaxKind.QuestionToken) : undefined; const parameterNode = createParameter( /*decorators*/ undefined, modifiers, @@ -4476,22 +4484,27 @@ namespace ts { // present (aka the tuple element property). This call also checks that the parentType is in // fact an iterable or array (depending on target language). const elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false, /*allowAsyncIterables*/ false); + const index = pattern.elements.indexOf(declaration); if (declaration.dotDotDotToken) { - // Rest element has an array type with the same element type as the parent type - type = createArrayType(elementType); + // If the parent is a tuple type, the rest element has an array type with a union of the + // remaining tuple element types. Otherwise, the rest element has an array type with same + // element type as the parent type. + type = isTupleType(parentType) ? + getArrayLiteralType((parentType.typeArguments || emptyArray).slice(index, getTypeReferenceArity(parentType))) : + createArrayType(elementType); } else { // Use specific property type when parent is a tuple or numeric index type when parent is an array - const propName = "" + pattern.elements.indexOf(declaration); - type = isTupleLikeType(parentType) - ? getTypeOfPropertyOfType(parentType, propName as __String) - : elementType; + const index = pattern.elements.indexOf(declaration); + type = isTupleLikeType(parentType) ? + getTupleElementType(parentType, index) || declaration.initializer && checkDeclarationInitializer(declaration) : + elementType; if (!type) { if (isTupleType(parentType)) { error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), getTypeReferenceArity(parentType), pattern.elements.length); } else { - error(declaration, Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); + error(declaration, Diagnostics.Type_0_has_no_property_1, typeToString(parentType), "" + index); } return errorType; } @@ -4762,7 +4775,7 @@ namespace ts { // pattern. Otherwise, it is the type any. function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean, reportErrors?: boolean): Type { if (element.initializer) { - return checkDeclarationInitializer(element); + return addOptionality(checkDeclarationInitializer(element)); } if (isBindingPattern(element.name)) { return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors); @@ -4810,12 +4823,13 @@ namespace ts { function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type { const elements = pattern.elements; const lastElement = lastOrUndefined(elements); - if (!lastElement || (!isOmittedExpression(lastElement) && lastElement.dotDotDotToken)) { + const hasRestElement = !!(lastElement && lastElement.kind === SyntaxKind.BindingElement && lastElement.dotDotDotToken); + if (elements.length === 0 || elements.length === 1 && hasRestElement) { return languageVersion >= ScriptTarget.ES2015 ? createIterableType(anyType) : anyArrayType; } - // If the pattern has at least one element, and no rest element, then it should imply a tuple type. const elementTypes = map(elements, e => isOmittedExpression(e) ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors)); - let result = createTupleType(elementTypes); + const minLength = findLastIndex(elements, e => !isOmittedExpression(e) && !hasDefaultValue(e), elements.length - (hasRestElement ? 2 : 1)) + 1; + let result = createTupleType(elementTypes, minLength, hasRestElement); if (includePatternInType) { result = cloneTypeReference(result); result.pattern = pattern; @@ -5424,7 +5438,7 @@ namespace ts { function getBaseTypes(type: InterfaceType): BaseType[] { if (!type.resolvedBaseTypes) { if (type.objectFlags & ObjectFlags.Tuple) { - type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters!))]; + type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters || emptyArray))]; } else if (type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { if (type.symbol.flags & SymbolFlags.Class) { @@ -6212,6 +6226,29 @@ namespace ts { /*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes); } + function getExpandedParameters(sig: Signature): ReadonlyArray { + if (sig.hasRestParameter) { + const restIndex = sig.parameters.length - 1; + const restParameter = sig.parameters[restIndex]; + const restType = getTypeOfSymbol(restParameter); + if (isTupleType(restType)) { + const elementTypes = restType.typeArguments || emptyArray; + const minLength = restType.target.minLength; + const tupleRestIndex = restType.target.hasRestElement ? elementTypes.length - 1 : -1; + const restParams = map(elementTypes, (t, i) => { + const name = getParameterNameAtPosition(sig, restIndex + i); + const checkFlags = i === tupleRestIndex ? CheckFlags.RestParameter : + i >= minLength ? CheckFlags.OptionalParameter : 0; + const symbol = createSymbol(SymbolFlags.FunctionScopedVariable, name, checkFlags); + symbol.type = i === tupleRestIndex ? createArrayType(t) : t; + return symbol; + }); + return concatenate(sig.parameters.slice(0, restIndex), restParams); + } + } + return sig.parameters; + } + function getDefaultConstructSignatures(classType: InterfaceType): Signature[] { const baseConstructorType = getBaseConstructorTypeOfClass(classType); const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct); @@ -7204,7 +7241,7 @@ namespace ts { const signature = getSignatureFromDeclaration(node.parent); const parameterIndex = node.parent.parameters.indexOf(node); Debug.assert(parameterIndex >= 0); - return parameterIndex >= signature.minArgumentCount; + return parameterIndex >= getMinArgumentCount(signature); } const iife = getImmediatelyInvokedFunctionExpression(node.parent); if (iife) { @@ -7390,9 +7427,8 @@ namespace ts { const lastParamVariadicType = firstDefined(lastParamTags, p => p.typeExpression && isJSDocVariadicType(p.typeExpression.type) ? p.typeExpression.type : undefined); - const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args" as __String); + const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args" as __String, CheckFlags.RestParameter); syntheticArgsSymbol.type = lastParamVariadicType ? createArrayType(getTypeFromTypeNode(lastParamVariadicType.type)) : anyArrayType; - syntheticArgsSymbol.isRestParameter = true; if (lastParamVariadicType) { // Replace the last parameter with a rest parameter. parameters.pop(); @@ -7556,14 +7592,9 @@ namespace ts { return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, TypeSystemPropertyName.ResolvedReturnType) >= 0; } - function getRestTypeOfSignature(signature: Signature): Type { - if (signature.hasRestParameter) { - const type = getTypeOfSymbol(last(signature.parameters)); - if (getObjectFlags(type) & ObjectFlags.Reference && (type).target === globalArrayType) { - return (type).typeArguments![0]; - } - } - return anyType; + function getRestTypeOfSignature(signature: Signature) { + const type = getTypeOfRestParameter(signature); + return type && getIndexTypeOfType(type, IndexKind.Number) || anyType; } function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean): Signature { @@ -7688,32 +7719,40 @@ namespace ts { let inferences: Type[] | undefined; if (typeParameter.symbol) { for (const declaration of typeParameter.symbol.declarations) { - // When an 'infer T' declaration is immediately contained in a type reference node - // (such as 'Foo'), T's constraint is inferred from the constraint of the - // corresponding type parameter in 'Foo'. When multiple 'infer T' declarations are - // present, we form an intersection of the inferred constraint types. - if (declaration.parent.kind === SyntaxKind.InferType && declaration.parent.parent.kind === SyntaxKind.TypeReference) { - const typeReference = declaration.parent.parent; - const typeParameters = getTypeParametersForTypeReference(typeReference); - if (typeParameters) { - const index = typeReference.typeArguments!.indexOf(declaration.parent); - if (index < typeParameters.length) { - const declaredConstraint = getConstraintOfTypeParameter(typeParameters[index]); - if (declaredConstraint) { - // Type parameter constraints can reference other type parameters so - // constraints need to be instantiated. If instantiation produces the - // type parameter itself, we discard that inference. For example, in - // type Foo = [T, U]; - // type Bar = T extends Foo ? Foo : T; - // the instantiated constraint for U is X, so we discard that inference. - const mapper = createTypeMapper(typeParameters, getEffectiveTypeArguments(typeReference, typeParameters)); - const constraint = instantiateType(declaredConstraint, mapper); - if (constraint !== typeParameter) { - inferences = append(inferences, constraint); + if (declaration.parent.kind === SyntaxKind.InferType) { + // When an 'infer T' declaration is immediately contained in a type reference node + // (such as 'Foo'), T's constraint is inferred from the constraint of the + // corresponding type parameter in 'Foo'. When multiple 'infer T' declarations are + // present, we form an intersection of the inferred constraint types. + const grandParent = declaration.parent.parent; + if (grandParent.kind === SyntaxKind.TypeReference) { + const typeReference = grandParent; + const typeParameters = getTypeParametersForTypeReference(typeReference); + if (typeParameters) { + const index = typeReference.typeArguments!.indexOf(declaration.parent); + if (index < typeParameters.length) { + const declaredConstraint = getConstraintOfTypeParameter(typeParameters[index]); + if (declaredConstraint) { + // Type parameter constraints can reference other type parameters so + // constraints need to be instantiated. If instantiation produces the + // type parameter itself, we discard that inference. For example, in + // type Foo = [T, U]; + // type Bar = T extends Foo ? Foo : T; + // the instantiated constraint for U is X, so we discard that inference. + const mapper = createTypeMapper(typeParameters, getEffectiveTypeArguments(typeReference, typeParameters)); + const constraint = instantiateType(declaredConstraint, mapper); + if (constraint !== typeParameter) { + inferences = append(inferences, constraint); + } } } } } + // When an 'infer T' declaration is immediately contained in a rest parameter + // declaration, we infer an 'unknown[]' constraint. + else if (grandParent.kind === SyntaxKind.Parameter && (grandParent).dotDotDotToken) { + inferences = append(inferences, createArrayType(unknownType)); + } } } } @@ -8267,20 +8306,27 @@ namespace ts { // // Note that the generic type created by this function has no symbol associated with it. The same // is true for each of the synthesized type parameters. - function createTupleTypeOfArity(arity: number): GenericType { - const typeParameters: TypeParameter[] = []; + function createTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, associatedNames: __String[] | undefined): TupleType { + let typeParameters: TypeParameter[] | undefined; const properties: Symbol[] = []; - for (let i = 0; i < arity; i++) { - const typeParameter = createType(TypeFlags.TypeParameter); - typeParameters.push(typeParameter); - const property = createSymbol(SymbolFlags.Property, "" + i as __String); - property.type = typeParameter; - properties.push(property); + const maxLength = hasRestElement ? arity - 1 : arity; + if (arity) { + typeParameters = new Array(arity); + for (let i = 0; i < arity; i++) { + const typeParameter = typeParameters[i] = createType(TypeFlags.TypeParameter); + if (i < maxLength) { + const property = createSymbol(SymbolFlags.Property | (i >= minLength ? SymbolFlags.Optional : 0), "" + i as __String); + property.type = typeParameter; + properties.push(property); + } + } } + const literalTypes = []; + for (let i = minLength; i <= maxLength; i++) literalTypes.push(getLiteralType(i)); const lengthSymbol = createSymbol(SymbolFlags.Property, "length" as __String); - lengthSymbol.type = getLiteralType(arity); + lengthSymbol.type = hasRestElement ? numberType : getUnionType(literalTypes); properties.push(lengthSymbol); - const type = createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference); + const type = createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference); type.typeParameters = typeParameters; type.outerTypeParameters = undefined; type.localTypeParameters = typeParameters; @@ -8296,25 +8342,50 @@ namespace ts { type.declaredConstructSignatures = emptyArray; type.declaredStringIndexInfo = undefined; type.declaredNumberIndexInfo = undefined; + type.minLength = minLength; + type.hasRestElement = hasRestElement; + type.associatedNames = associatedNames; return type; } - function getTupleTypeOfArity(arity: number): GenericType { - return tupleTypes[arity] || (tupleTypes[arity] = createTupleTypeOfArity(arity)); + function getTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, associatedNames?: __String[]): GenericType { + const key = arity + (hasRestElement ? "+" : ",") + minLength + (associatedNames && associatedNames.length ? "," + associatedNames.join(",") : ""); + let type = tupleTypes.get(key); + if (!type) { + tupleTypes.set(key, type = createTupleTypeOfArity(arity, minLength, hasRestElement, associatedNames)); + } + return type; } - function createTupleType(elementTypes: ReadonlyArray) { - return createTypeReference(getTupleTypeOfArity(elementTypes.length), elementTypes); + function createTupleType(elementTypes: ReadonlyArray, minLength = elementTypes.length, hasRestElement = false, associatedNames?: __String[]) { + const arity = elementTypes.length; + if (arity === 1 && hasRestElement) { + return createArrayType(elementTypes[0]); + } + const tupleType = getTupleTypeOfArity(arity, minLength, arity > 0 && hasRestElement, associatedNames); + return elementTypes.length ? createTypeReference(tupleType, elementTypes) : tupleType; } function getTypeFromTupleTypeNode(node: TupleTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = createTupleType(map(node.elementTypes, getTypeFromTypeNode)); + const lastElement = lastOrUndefined(node.elementTypes); + const restElement = lastElement && lastElement.kind === SyntaxKind.RestType ? lastElement : undefined; + const minLength = findLastIndex(node.elementTypes, n => n.kind !== SyntaxKind.OptionalType && n !== restElement) + 1; + const elementTypes = map(node.elementTypes, n => { + const type = getTypeFromTypeNode(n); + return n === restElement && getIndexTypeOfType(type, IndexKind.Number) || type; + }); + links.resolvedType = createTupleType(elementTypes, minLength, !!restElement); } return links.resolvedType; } + function getTypeFromOptionalTypeNode(node: OptionalTypeNode): Type { + const type = getTypeFromTypeNode(node.type); + return strictNullChecks ? getOptionalType(type) : type; + } + function getTypeId(type: Type) { return type.id; } @@ -8818,6 +8889,12 @@ namespace ts { } return getTypeOfSymbol(prop); } + if (isTupleType(objectType)) { + const restType = getRestTypeOfTupleType(objectType); + if (restType && isNumericLiteralName(propName) && +propName >= 0) { + return restType; + } + } } if (!(indexType.flags & TypeFlags.Nullable) && isTypeAssignableToKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbolLike)) { if (isTypeAny(objectType)) { @@ -9513,6 +9590,8 @@ namespace ts { return getTypeFromArrayTypeNode(node); case SyntaxKind.TupleType: return getTypeFromTupleTypeNode(node); + case SyntaxKind.OptionalType: + return getTypeFromOptionalTypeNode(node); case SyntaxKind.UnionType: return getTypeFromUnionTypeNode(node); case SyntaxKind.IntersectionType: @@ -9522,9 +9601,10 @@ namespace ts { case SyntaxKind.JSDocOptionalType: return addOptionality(getTypeFromTypeNode((node as JSDocOptionalType).type)); case SyntaxKind.ParenthesizedType: + case SyntaxKind.RestType: case SyntaxKind.JSDocNonNullableType: case SyntaxKind.JSDocTypeExpression: - return getTypeFromTypeNode((node).type); + return getTypeFromTypeNode((node).type); case SyntaxKind.JSDocVariadicType: return getTypeFromJSDocVariadicType(node as JSDocVariadicType); case SyntaxKind.FunctionType: @@ -9719,7 +9799,7 @@ namespace ts { } // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. - const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | (getCheckFlags(symbol) & CheckFlags.Late)); + const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | getCheckFlags(symbol) & (CheckFlags.Late | CheckFlags.OptionalParameter | CheckFlags.RestParameter)); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -9730,11 +9810,6 @@ namespace ts { if (symbol.nameType) { result.nameType = symbol.nameType; } - if (isTransientSymbol(symbol)) { - if (symbol.isRestParameter) { - result.isRestParameter = symbol.isRestParameter; - } - } return result; } @@ -10130,7 +10205,9 @@ namespace ts { if (source === target) { return Ternary.True; } - if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { + + const targetCount = getParameterCount(target); + if (!hasEffectiveRestParameter(target) && getMinArgumentCount(source) > targetCount) { return Ternary.False; } @@ -10139,6 +10216,13 @@ namespace ts { source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } + const sourceCount = getParameterCount(source); + const sourceRestTypeParameter = getRestTypeParameter(source); + const targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; + if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + return Ternary.False; + } + const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown; const strictVariance = !callbackCheck && strictFunctionTypes && kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature && kind !== SyntaxKind.Constructor; @@ -10161,14 +10245,11 @@ namespace ts { } } - const sourceMax = getNumNonRestParameters(source); - const targetMax = getNumNonRestParameters(target); - const checkCount = getNumParametersToCheckForSignatureRelatability(source, sourceMax, target, targetMax); - const sourceParams = source.parameters; - const targetParams = target.parameters; - for (let i = 0; i < checkCount; i++) { - const sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source); - const targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target); + const paramCount = Math.max(sourceCount, targetCount); + const lastIndex = paramCount - 1; + for (let i = 0; i < paramCount; i++) { + const sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); + const targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -10188,8 +10269,8 @@ namespace ts { if (!related) { if (reportErrors) { errorReporter!(Diagnostics.Types_of_parameters_0_and_1_are_incompatible, - symbolName(sourceParams[i < sourceMax ? i : sourceMax]), - symbolName(targetParams[i < targetMax ? i : targetMax])); + unescapeLeadingUnderscores(getParameterNameAtPosition(source, i)), + unescapeLeadingUnderscores(getParameterNameAtPosition(target, i))); } return Ternary.False; } @@ -10283,32 +10364,6 @@ namespace ts { return false; } - function getNumNonRestParameters(signature: Signature) { - const numParams = signature.parameters.length; - return signature.hasRestParameter ? - numParams - 1 : - numParams; - } - - function getNumParametersToCheckForSignatureRelatability(source: Signature, sourceNonRestParamCount: number, target: Signature, targetNonRestParamCount: number) { - if (source.hasRestParameter === target.hasRestParameter) { - if (source.hasRestParameter) { - // If both have rest parameters, get the max and add 1 to - // compensate for the rest parameter. - return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; - } - else { - return Math.min(sourceNonRestParamCount, targetNonRestParamCount); - } - } - else { - // Return the count for whichever signature doesn't have rest parameters. - return source.hasRestParameter ? - targetNonRestParamCount : - sourceNonRestParamCount; - } - } - function isEmptyResolvedType(t: ResolvedType) { return t.properties.length === 0 && t.callSignatures.length === 0 && @@ -11274,7 +11329,7 @@ namespace ts { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } - const requireOptionalProperties = relation === subtypeRelation && !isObjectLiteralType(source) && !isEmptyArrayLiteralType(source); + const requireOptionalProperties = relation === subtypeRelation && !isObjectLiteralType(source) && !isEmptyArrayLiteralType(source) && !isTupleType(source); const unmatchedProperty = getUnmatchedProperty(source, target, requireOptionalProperties); if (unmatchedProperty) { if (reportErrors) { @@ -11296,6 +11351,33 @@ namespace ts { } } let result = Ternary.True; + if (isTupleType(target)) { + const targetRestType = getRestTypeOfTupleType(target); + if (targetRestType) { + if (!isTupleType(source)) { + return Ternary.False; + } + const sourceRestType = getRestTypeOfTupleType(source); + if (sourceRestType && !isRelatedTo(sourceRestType, targetRestType, reportErrors)) { + if (reportErrors) { + reportError(Diagnostics.Rest_signatures_are_incompatible); + } + return Ternary.False; + } + const targetCount = getTypeReferenceArity(target) - 1; + const sourceCount = getTypeReferenceArity(source) - (sourceRestType ? 1 : 0); + for (let i = targetCount; i < sourceCount; i++) { + const related = isRelatedTo((source).typeArguments![i], targetRestType, reportErrors); + if (!related) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_incompatible_with_rest_element_type, "" + i); + } + return Ternary.False; + } + result &= related; + } + } + } const properties = getPropertiesOfObjectType(target); for (const targetProp of properties) { if (!(targetProp.flags & SymbolFlags.Prototype)) { @@ -11851,21 +11933,27 @@ namespace ts { } function isMatchingSignature(source: Signature, target: Signature, partialMatch: boolean) { + const sourceParameterCount = getParameterCount(source); + const targetParameterCount = getParameterCount(target); + const sourceMinArgumentCount = getMinArgumentCount(source); + const targetMinArgumentCount = getMinArgumentCount(target); + const sourceHasRestParameter = hasEffectiveRestParameter(source); + const targetHasRestParameter = hasEffectiveRestParameter(target); // A source signature matches a target signature if the two signatures have the same number of required, // optional, and rest parameters. - if (source.parameters.length === target.parameters.length && - source.minArgumentCount === target.minArgumentCount && - source.hasRestParameter === target.hasRestParameter) { + if (sourceParameterCount === targetParameterCount && + sourceMinArgumentCount === targetMinArgumentCount && + sourceHasRestParameter === targetHasRestParameter) { return true; } // A source signature partially matches a target signature if the target signature has no fewer required // parameters and no more overall parameters than the source signature (where a signature with a rest // parameter is always considered to have more overall parameters than one without). - const sourceRestCount = source.hasRestParameter ? 1 : 0; - const targetRestCount = target.hasRestParameter ? 1 : 0; - if (partialMatch && source.minArgumentCount <= target.minArgumentCount && ( + const sourceRestCount = sourceHasRestParameter ? 1 : 0; + const targetRestCount = targetHasRestParameter ? 1 : 0; + if (partialMatch && sourceMinArgumentCount <= targetMinArgumentCount && ( sourceRestCount > targetRestCount || - sourceRestCount === targetRestCount && source.parameters.length >= target.parameters.length)) { + sourceRestCount === targetRestCount && sourceParameterCount >= targetParameterCount)) { return true; } return false; @@ -11910,10 +11998,10 @@ namespace ts { } } - const targetLen = target.parameters.length; + const targetLen = getParameterCount(target); for (let i = 0; i < targetLen; i++) { - const s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfParameter(source.parameters[i]); - const t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfParameter(target.parameters[i]); + const s = getTypeAtPosition(source, i); + const t = getTypeAtPosition(target, i); const related = compareTypes(s, t); if (!related) { return Ternary.False; @@ -11935,10 +12023,6 @@ namespace ts { return source === undefined || target === undefined || !typePredicateKindsMatch(source, target) ? Ternary.False : compareTypes(source.type, target.type); } - function isRestParameterIndex(signature: Signature, parameterIndex: number) { - return signature.hasRestParameter && parameterIndex >= signature.parameters.length - 1; - } - function literalTypesWithSameBaseType(types: Type[]): boolean { let commonBaseType: Type | undefined; for (const t of types) { @@ -11994,7 +12078,13 @@ namespace ts { } function isTupleLikeType(type: Type): boolean { - return !!getPropertyOfType(type, "0" as __String); + return isTupleType(type) || !!getPropertyOfType(type, "0" as __String); + } + + function getTupleElementType(type: Type, index: number) { + return isTupleType(type) ? + index < getLengthOfTupleType(type) ? type.typeArguments![index] : getRestTypeOfTupleType(type) : + getTypeOfPropertyOfType(type, "" + index as __String); } function isNeitherUnitTypeNorNever(type: Type): boolean { @@ -12046,10 +12136,18 @@ namespace ts { * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ - function isTupleType(type: Type): boolean { + function isTupleType(type: Type): type is TupleTypeReference { return !!(getObjectFlags(type) & ObjectFlags.Reference && (type).target.objectFlags & ObjectFlags.Tuple); } + function getRestTypeOfTupleType(type: TupleTypeReference) { + return type.target.hasRestElement ? type.typeArguments![type.target.typeParameters!.length - 1] : undefined; + } + + function getLengthOfTupleType(type: TupleTypeReference) { + return getTypeReferenceArity(type) - (type.target.hasRestElement ? 1 : 0); + } + function getFalsyFlagsOfTypes(types: Type[]): TypeFlags { let result: TypeFlags = 0; for (const t of types) { @@ -12387,24 +12485,37 @@ namespace ts { } function forEachMatchingParameterType(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) { - const sourceMax = source.parameters.length; - const targetMax = target.parameters.length; - let count: number; - if (source.hasRestParameter && target.hasRestParameter) { - count = Math.max(sourceMax, targetMax); - } - else if (source.hasRestParameter) { - count = targetMax; - } - else if (target.hasRestParameter) { - count = sourceMax; - } - else { - count = Math.min(sourceMax, targetMax); - } - for (let i = 0; i < count; i++) { + const sourceCount = getParameterCount(source); + const targetCount = getParameterCount(target); + const sourceHasRest = hasEffectiveRestParameter(source); + const targetHasRest = hasEffectiveRestParameter(target); + const maxCount = sourceHasRest && targetHasRest ? Math.max(sourceCount, targetCount) : + sourceHasRest ? targetCount : + targetHasRest ? sourceCount : + Math.min(sourceCount, targetCount); + const targetRestTypeVariable = getRestTypeParameter(target); + const paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + for (let i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } + if (targetRestTypeVariable) { + const sourceRestTypeVariable = getRestTypeParameter(source); + if (sourceRestTypeVariable && paramCount === sourceCount - 1) { + callback(sourceRestTypeVariable, targetRestTypeVariable); + } + else { + const types = []; + const names = []; + for (let i = paramCount; i < maxCount; i++) { + types.push(getTypeAtPosition(source, i)); + names.push(getParameterNameAtPosition(source, i)); + } + const minArgumentCount = getMinArgumentCount(source); + const minLength = minArgumentCount < paramCount ? 0 : minArgumentCount - paramCount; + const rest = createTupleType(types, minLength, sourceHasRest, names); + callback(rest, targetRestTypeVariable); + } + } } function createInferenceContext(typeParameters: ReadonlyArray, signature: Signature | undefined, flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext { @@ -12555,10 +12666,15 @@ namespace ts { return undefined; } + function tupleTypesDefinitelyUnrelated(source: TupleTypeReference, target: TupleTypeReference) { + return target.target.minLength > source.target.minLength || + !getRestTypeOfTupleType(target) && (!!getRestTypeOfTupleType(source) || getLengthOfTupleType(target) < getLengthOfTupleType(source)); + } + function typesDefinitelyUnrelated(source: Type, target: Type) { - // Two tuple types with different arity are definitely unrelated. + // Two tuple types with incompatible arities are definitely unrelated. // Two object types that each have a property that is unmatched in the other are definitely unrelated. - return isTupleType(source) && isTupleType(target) && getTypeReferenceArity(source) !== getTypeReferenceArity(target) || + return isTupleType(source) && isTupleType(target) && tupleTypesDefinitelyUnrelated(source, target) || !!getUnmatchedProperty(source, target, /*requireOptionalProperties*/ false) && !!getUnmatchedProperty(target, source, /*requireOptionalProperties*/ false); } @@ -12842,11 +12958,32 @@ namespace ts { } function inferFromProperties(source: Type, target: Type) { - const properties = getPropertiesOfObjectType(target); - for (const targetProp of properties) { - const sourceProp = getPropertyOfType(source, targetProp.escapedName); - if (sourceProp) { - inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); + if (isTupleType(source) && isTupleType(target)) { + const sourceLength = getLengthOfTupleType(source); + const targetLength = getLengthOfTupleType(target); + const sourceRestType = getRestTypeOfTupleType(source); + const targetRestType = getRestTypeOfTupleType(target); + const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength; + for (let i = 0; i < fixedLength; i++) { + inferFromTypes(i < sourceLength ? source.typeArguments![i] : sourceRestType!, target.typeArguments![i]); + } + if (targetRestType) { + const types = fixedLength < sourceLength ? source.typeArguments!.slice(fixedLength, sourceLength) : []; + if (sourceRestType) { + types.push(sourceRestType); + } + if (types.length) { + inferFromTypes(getUnionType(types), targetRestType); + } + } + } + else { + const properties = getPropertiesOfObjectType(target); + for (const targetProp of properties) { + const sourceProp = getPropertyOfType(source, targetProp.escapedName); + if (sourceProp) { + inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); + } } } } @@ -12971,17 +13108,14 @@ namespace ts { if (!inferredType) { const signature = context.signature; if (signature) { + if (inference.contraCandidates) { + // If we have contravariant inferences we find the best common subtype and treat + // that as a single covariant candidate. + inference.candidates = append(inference.candidates, getContravariantInference(inference)); + inference.contraCandidates = undefined; + } if (inference.candidates) { inferredType = getCovariantInference(inference, context, signature); - // If we have inferred 'never' but have contravariant candidates. To get a more specific type we - // infer from the contravariant candidates instead. - if (inferredType.flags & TypeFlags.Never && inference.contraCandidates) { - inferredType = getContravariantInference(inference); - } - } - else if (inference.contraCandidates) { - // We only have contravariant inferences, infer the best common subtype of those - inferredType = getContravariantInference(inference); } else if (context.flags & InferenceFlags.NoDefault) { // We use silentNeverType as the wildcard that signals no inferences. @@ -13348,7 +13482,7 @@ namespace ts { } function getTypeOfDestructuredArrayElement(type: Type, index: number) { - return isTupleLikeType(type) && getTypeOfPropertyOfType(type, "" + index as __String) || + return isTupleLikeType(type) && getTupleElementType(type, index) || checkIteratedTypeOrElementType(type, /*errorNode*/ undefined, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType; } @@ -15215,9 +15349,10 @@ namespace ts { // If last parameter is contextually rest parameter get its type if (funcHasRestParameters && - indexOfParameter === (func.parameters.length - 1) && - isRestParameterIndex(contextualSignature, func.parameters.length - 1)) { - return getTypeOfSymbol(last(contextualSignature.parameters)); + indexOfParameter === func.parameters.length - 1 && + hasEffectiveRestParameter(contextualSignature) && + func.parameters.length >= contextualSignature.parameters.length) { + return getTypeOfRestParameter(contextualSignature); } } } @@ -15396,8 +15531,19 @@ namespace ts { function getTypeOfPropertyOfContextualType(type: Type, name: __String) { return mapType(type, t => { - const prop = t.flags & TypeFlags.StructuredType ? getPropertyOfType(t, name) : undefined; - return prop ? getTypeOfSymbol(prop) : undefined; + if (t.flags & TypeFlags.StructuredType) { + const prop = getPropertyOfType(t, name); + if (prop) { + return getTypeOfSymbol(prop); + } + if (isTupleType(t)) { + const restType = getRestTypeOfTupleType(t); + if (restType && isNumericLiteralName(name) && +name >= 0) { + return restType; + } + } + } + return undefined; }, /*noReductions*/ true); } @@ -15781,8 +15927,7 @@ namespace ts { if (target.parameters.length && parameterIsThisKeyword(target.parameters[0])) { targetParameterCount--; } - const sourceLength = signature.hasRestParameter ? Number.MAX_VALUE : signature.parameters.length; - return sourceLength < targetParameterCount; + return !hasEffectiveRestParameter(signature) && getParameterCount(signature) < targetParameterCount; } function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction { @@ -15870,11 +16015,12 @@ namespace ts { function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined): Type { const elements = node.elements; - let hasSpreadElement = false; + const elementCount = elements.length; + let hasNonEndingSpreadElement = false; const elementTypes: Type[] = []; const inDestructuringPattern = isAssignmentTarget(node); const contextualType = getApparentTypeOfContextualType(node); - for (let index = 0; index < elements.length; index++) { + for (let index = 0; index < elementCount; index++) { const e = elements[index]; if (inDestructuringPattern && e.kind === SyntaxKind.SpreadElement) { // Given the following situation: @@ -15901,13 +16047,17 @@ namespace ts { const type = checkExpressionForMutableLocation(e, checkMode, elementContextualType); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElement; + if (index < elementCount - 1 && e.kind === SyntaxKind.SpreadElement) { + hasNonEndingSpreadElement = true; + } } - if (!hasSpreadElement) { + if (!hasNonEndingSpreadElement) { + const hasRestElement = elementCount > 0 && elements[elementCount - 1].kind === SyntaxKind.SpreadElement; + const minLength = elementCount - (hasRestElement ? 1 : 0); // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". - if (inDestructuringPattern && elementTypes.length) { - const type = cloneTypeReference(createTupleType(elementTypes)); + if (inDestructuringPattern && minLength > 0) { + const type = cloneTypeReference(createTupleType(elementTypes, minLength, hasRestElement)); type.pattern = node; return type; } @@ -15915,28 +16065,30 @@ namespace ts { const pattern = contextualType.pattern; // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting // tuple type with the corresponding binding or assignment element types to make the lengths equal. - if (pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { + if (!hasRestElement && pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { const patternElements = (pattern).elements; - for (let i = elementTypes.length; i < patternElements.length; i++) { - const patternElement = patternElements[i]; - if (hasDefaultValue(patternElement)) { + for (let i = elementCount; i < patternElements.length; i++) { + const e = patternElements[i]; + if (hasDefaultValue(e)) { elementTypes.push((contextualType).typeArguments![i]); } - else { - if (patternElement.kind !== SyntaxKind.OmittedExpression) { - error(patternElement, Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); + else if (i < patternElements.length - 1 || !(e.kind === SyntaxKind.BindingElement && (e).dotDotDotToken || e.kind === SyntaxKind.SpreadElement)) { + if (e.kind !== SyntaxKind.OmittedExpression) { + error(e, Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(strictNullChecks ? implicitNeverType : undefinedWideningType); } } } - if (elementTypes.length) { - return createTupleType(elementTypes); - } + return createTupleType(elementTypes, minLength, hasRestElement); } } + return getArrayLiteralType(elementTypes, UnionReduction.Subtype); + } + + function getArrayLiteralType(elementTypes: Type[], unionReduction = UnionReduction.Literal) { return createArrayType(elementTypes.length ? - getUnionType(elementTypes, UnionReduction.Subtype) : + getUnionType(elementTypes, unionReduction) : strictNullChecks ? implicitNeverType : undefinedWideningType); } @@ -17730,14 +17882,12 @@ namespace ts { } } + function isSpreadArgument(arg: Expression | undefined) { + return !!arg && (arg.kind === SyntaxKind.SpreadElement || arg.kind === SyntaxKind.SyntheticExpression && (arg).isSpread); + } + function getSpreadArgumentIndex(args: ReadonlyArray): number { - for (let i = 0; i < args.length; i++) { - const arg = args[i]; - if (arg && arg.kind === SyntaxKind.SpreadElement) { - return i; - } - } - return -1; + return findIndex(args, isSpreadArgument); } function hasCorrectArity(node: CallLikeExpression, args: ReadonlyArray, signature: Signature, signatureHelpTrailingComma = false) { @@ -17780,8 +17930,7 @@ namespace ts { if (!node.arguments) { // This only happens when we have something of the form: 'new C' Debug.assert(node.kind === SyntaxKind.NewExpression); - - return signature.minArgumentCount === 0; + return getMinArgumentCount(signature) === 0; } argCount = signatureHelpTrailingComma ? args.length + 1 : args.length; @@ -17799,17 +17948,16 @@ namespace ts { // If a spread argument is present, check that it corresponds to a rest parameter or at least that it's in the valid range. if (spreadArgIndex >= 0) { - return isRestParameterIndex(signature, spreadArgIndex) || - signature.minArgumentCount <= spreadArgIndex && spreadArgIndex < signature.parameters.length; + return spreadArgIndex >= getMinArgumentCount(signature) && (hasEffectiveRestParameter(signature) || spreadArgIndex < getParameterCount(signature)); } // Too many arguments implies incorrect arity. - if (!signature.hasRestParameter && argCount > signature.parameters.length) { + if (!hasEffectiveRestParameter(signature) && argCount > getParameterCount(signature)) { return false; } // If the call is incomplete, we should skip the lower bound check. - const hasEnoughArguments = argCount >= signature.minArgumentCount; + const hasEnoughArguments = argCount >= getMinArgumentCount(signature); return callIsIncomplete || hasEnoughArguments; } @@ -17837,9 +17985,10 @@ namespace ts { // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper?: TypeMapper, compareTypes?: TypeComparer): Signature { const context = createInferenceContext(signature.typeParameters!, signature, InferenceFlags.InferUnionTypes, compareTypes); - forEachMatchingParameterType(contextualSignature, signature, (source, target) => { + const sourceSignature = contextualMapper ? instantiateSignature(contextualSignature, contextualMapper) : contextualSignature; + forEachMatchingParameterType(sourceSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context.inferences, instantiateType(source, contextualMapper || identityMapper), target); + inferTypes(context.inferences, source, target); }); if (!contextualMapper) { inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType); @@ -17910,14 +18059,15 @@ namespace ts { // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. - const argCount = getEffectiveArgumentCount(node, args, signature); + const effectiveArgCount = getEffectiveArgumentCount(node, args, signature); + const restTypeParameter = getRestTypeParameter(signature); + const argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (let i = 0; i < argCount; i++) { const arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { const paramType = getTypeAtPosition(signature, i); let argType = getEffectiveArgumentType(node, i); - // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. if (argType === undefined) { @@ -17926,11 +18076,15 @@ namespace ts { const mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : context; argType = checkExpressionWithContextualType(arg!, paramType, mapper); } - inferTypes(context.inferences, argType, paramType); } } + if (restTypeParameter) { + const spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); + inferTypes(context.inferences, spreadType, restTypeParameter); + } + // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed // as we construct types for contextually typed parameters) @@ -17949,6 +18103,34 @@ namespace ts { return getInferredTypes(context); } + function getSpreadArgumentType(node: CallLikeExpression, args: ReadonlyArray, index: number, argCount: number, restType: TypeParameter, context: InferenceContext | undefined) { + if (index === argCount - 1) { + const arg = getEffectiveArgument(node, args, index); + if (isSpreadArgument(arg)) { + // We are inferring from a spread expression in the last argument position, i.e. both the parameter + // and the argument are ...x forms. + return checkExpressionWithContextualType((arg).expression, restType, context); + } + } + const contextualType = getIndexTypeOfType(restType, IndexKind.Number) || anyType; + const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, TypeFlags.Primitive | TypeFlags.Index); + const types = []; + let spreadIndex = -1; + for (let i = index; i < argCount; i++) { + let argType = getEffectiveArgumentType(node, i); + if (!argType) { + argType = checkExpressionWithContextualType(args[i], contextualType, context); + if (spreadIndex < 0 && isSpreadArgument(args[i])) { + spreadIndex = i - index; + } + } + types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType)); + } + return spreadIndex < 0 ? + createTupleType(types) : + createTupleType(append(types.slice(0, spreadIndex), getUnionType(types.slice(spreadIndex))), spreadIndex, /*hasRestElement*/ true); + } + function checkTypeArguments(signature: Signature, typeArgumentNodes: ReadonlyArray, reportErrors: boolean, headMessage?: DiagnosticMessage): Type[] | false { const isJavascript = isInJavaScriptFile(signature.declaration); const typeParameters = signature.typeParameters!; @@ -18036,28 +18218,35 @@ namespace ts { } const headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; const argCount = getEffectiveArgumentCount(node, args, signature); + const restIndex = signature.hasRestParameter ? signature.parameters.length - 1 : -1; + const restType = restIndex >= 0 ? getTypeOfSymbol(signature.parameters[restIndex]) : anyType; for (let i = 0; i < argCount; i++) { const arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { - // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) - const paramType = getTypeAtPosition(signature, i); - // If the effective argument type is undefined, there is no synthetic type for the argument. - // In that case, we should check the argument. - const argType = getEffectiveArgumentType(node, i) || - checkExpressionWithContextualType(arg!, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); - // If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter), - // we obtain the regular type of any object literal arguments because we may not have inferred complete - // parameter types yet and therefore excess property checks may yield false positives (see #17041). - const checkArgType = excludeArgument ? getRegularTypeOfObjectLiteral(argType) : argType; - // Use argument expression as error location when reporting errors - const errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; - if (!checkTypeRelatedTo(checkArgType, paramType, relation, errorNode, headMessage)) { - return false; + if (i === restIndex && (restType.flags & TypeFlags.TypeParameter || isSpreadArgument(arg) && !isArrayType(restType))) { + const spreadType = getSpreadArgumentType(node, args, i, argCount, restType, /*context*/ undefined); + return checkTypeRelatedTo(spreadType, restType, relation, arg, headMessage); + } + else { + // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) + const paramType = getTypeAtPosition(signature, i); + // If the effective argument type is undefined, there is no synthetic type for the argument. + // In that case, we should check the argument. + const argType = getEffectiveArgumentType(node, i) || + checkExpressionWithContextualType(arg!, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + // If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter), + // we obtain the regular type of any object literal arguments because we may not have inferred complete + // parameter types yet and therefore excess property checks may yield false positives (see #17041). + const checkArgType = excludeArgument ? getRegularTypeOfObjectLiteral(argType) : argType; + // Use argument expression as error location when reporting errors + const errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + if (!checkTypeRelatedTo(checkArgType, paramType, relation, errorNode, headMessage)) { + return false; + } } } } - return true; } @@ -18103,7 +18292,28 @@ namespace ts { return node.attributes.properties.length > 0 ? [node.attributes] : emptyArray; } else { - return node.arguments || emptyArray; + const args = node.arguments || emptyArray; + const length = args.length; + if (length && isSpreadArgument(args[length - 1]) && getSpreadArgumentIndex(args) === length - 1) { + // We have a spread argument in the last position and no other spread arguments. If the type + // of the argument is a tuple type, spread the tuple elements into the argument list. We can + // call checkExpressionCached because spread expressions never have a contextual type. + const spreadArgument = args[length - 1]; + const type = checkExpressionCached(spreadArgument.expression); + if (isTupleType(type)) { + const typeArguments = (type).typeArguments || emptyArray; + const restIndex = type.target.hasRestElement ? typeArguments.length - 1 : -1; + const syntheticArgs = map(typeArguments, (t, i) => { + const arg = createNode(SyntaxKind.SyntheticExpression, spreadArgument.pos, spreadArgument.end); + arg.parent = spreadArgument; + arg.type = t; + arg.isSpread = i === restIndex; + return arg; + }); + return concatenate(args.slice(0, length - 1), syntheticArgs); + } + } + return args; } } @@ -18527,10 +18737,10 @@ namespace ts { let min = Number.POSITIVE_INFINITY; let max = Number.NEGATIVE_INFINITY; for (const sig of signatures) { - min = Math.min(min, sig.minArgumentCount); - max = Math.max(max, sig.parameters.length); + min = Math.min(min, getMinArgumentCount(sig)); + max = Math.max(max, getParameterCount(sig)); } - const hasRestParameter = some(signatures, sig => sig.hasRestParameter); + const hasRestParameter = some(signatures, hasEffectiveRestParameter); const hasSpreadArgument = getSpreadArgumentIndex(args) > -1; const paramCount = hasRestParameter ? min : min < max ? min + "-" + max : @@ -18657,11 +18867,12 @@ namespace ts { for (let i = 0; i < candidates.length; i++) { const candidate = candidates[i]; - if (candidate.hasRestParameter || candidate.parameters.length >= argsCount) { + const paramCount = getParameterCount(candidate); + if (hasEffectiveRestParameter(candidate) || paramCount >= argsCount) { return i; } - if (candidate.parameters.length > maxParams) { - maxParams = candidate.parameters.length; + if (paramCount > maxParams) { + maxParams = paramCount; maxParamsIndex = i; } } @@ -19389,12 +19600,94 @@ namespace ts { return type; } + function getParameterNameAtPosition(signature: Signature, pos: number) { + const paramCount = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); + if (pos < paramCount) { + return signature.parameters[pos].escapedName; + } + const restParameter = signature.parameters[paramCount] || unknownSymbol; + const restType = getTypeOfSymbol(restParameter); + if (isTupleType(restType)) { + const associatedNames = ((restType).target).associatedNames; + const index = pos - paramCount; + return associatedNames ? associatedNames[index] : restParameter.escapedName + "_" + index as __String; + } + return restParameter.escapedName; + } + function getTypeAtPosition(signature: Signature, pos: number): Type { - return signature.hasRestParameter ? - pos < signature.parameters.length - 1 ? getTypeOfParameter(signature.parameters[pos]) : getRestTypeOfSignature(signature) : - pos < signature.parameters.length ? getTypeOfParameter(signature.parameters[pos]) : anyType; + const paramCount = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); + if (pos < paramCount) { + return getTypeOfParameter(signature.parameters[pos]); + } + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[paramCount]); + if (isTupleType(restType)) { + if (pos - paramCount < getLengthOfTupleType(restType)) { + return restType.typeArguments![pos - paramCount]; + } + const tupleRestType = getRestTypeOfTupleType(restType); + if (tupleRestType) { + return tupleRestType; + } + } + return getIndexTypeOfType(restType, IndexKind.Number) || anyType; + } + return anyType; + } + + function getTypeOfRestParameter(signature: Signature) { + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); + if (isTupleType(restType)) { + return getRestTypeOfTupleType(restType); + } + return restType; + } + return undefined; + } + + function getParameterCount(signature: Signature) { + const length = signature.parameters.length; + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[length - 1]); + if (isTupleType(restType)) { + return length + (restType.typeArguments || emptyArray).length - 1; + } + } + return length; + } + + function getMinArgumentCount(signature: Signature) { + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); + if (isTupleType(restType)) { + const minLength = restType.target.minLength; + if (minLength > 0) { + return signature.parameters.length - 1 + minLength; + } + } + } + return signature.minArgumentCount; + } + + function getRestTypeParameter(signature: Signature) { + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); + if (restType.flags & TypeFlags.TypeParameter) { + return restType; + } + } + return undefined; } + function hasEffectiveRestParameter(signature: Signature) { + if (signature.hasRestParameter) { + const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); + return !isTupleType(restType) || restType.target.hasRestElement; + } + return false; + } function getTypeOfFirstParameterOfSignature(signature: Signature) { return getTypeOfFirstParameterOfSignatureWithFallback(signature, neverType); @@ -19436,7 +19729,7 @@ namespace ts { assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); } } - if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { + if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) { // parameter might be a transient symbol generated by use of `arguments` in the function body. const parameter = last(signature.parameters); if (isTransientSymbol(parameter) || !getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { @@ -20183,24 +20476,20 @@ namespace ts { if (element.kind !== SyntaxKind.OmittedExpression) { if (element.kind !== SyntaxKind.SpreadElement) { const propName = "" + elementIndex as __String; - const type = isTypeAny(sourceType) - ? sourceType - : isTupleLikeType(sourceType) - ? getTypeOfPropertyOfType(sourceType, propName) - : elementType; + const type = isTypeAny(sourceType) ? sourceType : + isTupleLikeType(sourceType) ? getTupleElementType(sourceType, elementIndex) : + elementType; if (type) { return checkDestructuringAssignment(element, type, checkMode); } + // We still need to check element expression here because we may need to set appropriate flag on the expression + // such as NodeCheckFlags.LexicalThis on "this"expression. + checkExpression(element); + if (isTupleType(sourceType)) { + error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), getTypeReferenceArity(sourceType), elements.length); + } else { - // We still need to check element expression here because we may need to set appropriate flag on the expression - // such as NodeCheckFlags.LexicalThis on "this"expression. - checkExpression(element); - if (isTupleType(sourceType)) { - error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), getTypeReferenceArity(sourceType), elements.length); - } - else { - error(element, Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName as string); - } + error(element, Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName as string); } } else { @@ -20214,7 +20503,10 @@ namespace ts { } else { checkGrammarForDisallowedTrailingComma(node.elements, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma); - return checkDestructuringAssignment(restExpression, createArrayType(elementType), checkMode); + const type = isTupleType(sourceType) ? + getArrayLiteralType((sourceType.typeArguments || emptyArray).slice(elementIndex, getTypeReferenceArity(sourceType))) : + createArrayType(elementType); + return checkDestructuringAssignment(restExpression, type, checkMode); } } } @@ -20982,6 +21274,8 @@ namespace ts { return undefinedWideningType; case SyntaxKind.YieldExpression: return checkYieldExpression(node); + case SyntaxKind.SyntheticExpression: + return (node).type; case SyntaxKind.JsxExpression: return checkJsxExpression(node, checkMode); case SyntaxKind.JsxElement: @@ -21025,6 +21319,10 @@ namespace ts { } } + function isRestParameterType(type: Type) { + return isArrayType(type) || isTupleType(type) || type.flags & TypeFlags.Instantiable && isTypeAssignableTo(type, anyArrayType); + } + function checkParameter(node: ParameterDeclaration) { // Grammar checking // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the @@ -21053,7 +21351,7 @@ namespace ts { // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. - if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { + if (node.dotDotDotToken && !isBindingPattern(node.name) && !isRestParameterType(getTypeOfSymbol(node.symbol))) { error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } @@ -21668,12 +21966,28 @@ namespace ts { } function checkTupleType(node: TupleTypeNode) { - // Grammar checking - const hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes); - if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) { - grammarErrorOnNode(node, Diagnostics.A_tuple_type_element_list_cannot_be_empty); + const elementTypes = node.elementTypes; + let seenOptionalElement = false; + for (let i = 0; i < elementTypes.length; i++) { + const e = elementTypes[i]; + if (e.kind === SyntaxKind.RestType) { + if (i !== elementTypes.length - 1) { + grammarErrorOnNode(e, Diagnostics.A_rest_element_must_be_last_in_a_tuple_type); + break; + } + if (!isArrayType(getTypeFromTypeNode(e))) { + error(e, Diagnostics.A_rest_element_type_must_be_an_array_type); + } + } + else if (e.kind === SyntaxKind.OptionalType) { + seenOptionalElement = true; + } + else if (seenOptionalElement) { + grammarErrorOnNode(e, Diagnostics.A_required_element_cannot_follow_an_optional_element); + break; + } } - + checkGrammarForDisallowedTrailingComma(node.elementTypes); forEach(node.elementTypes, checkSourceElement); } @@ -25558,7 +25872,9 @@ namespace ts { case SyntaxKind.IntersectionType: return checkUnionOrIntersectionType(node); case SyntaxKind.ParenthesizedType: - return checkSourceElement((node).type); + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: + return checkSourceElement((node).type); case SyntaxKind.TypeOperator: return checkTypeOperator(node); case SyntaxKind.ConditionalType: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7d08fd5caf120..53e9f0c30bfaa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -367,10 +367,6 @@ "category": "Error", "code": 1121 }, - "A tuple type element list cannot be empty.": { - "category": "Error", - "code": 1122 - }, "Variable declaration list cannot be empty.": { "category": "Error", "code": 1123 @@ -847,6 +843,14 @@ "category": "Error", "code": 1255 }, + "A rest element must be last in a tuple type.": { + "category": "Error", + "code": 1256 + }, + "A required element cannot follow an optional element.": { + "category": "Error", + "code": 1257 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 @@ -2032,6 +2036,18 @@ "category": "Error", "code": 2571 }, + "Rest signatures are incompatible.": { + "category": "Error", + "code": 2572 + }, + "Property '{0}' is incompatible with rest element type.": { + "category": "Error", + "code": 2573 + }, + "A rest element type must be an array type.": { + "category": "Error", + "code": 2574 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1857fa05f60d8..641c9a0953f30 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -659,6 +659,8 @@ namespace ts { return emitArrayType(node); case SyntaxKind.TupleType: return emitTupleType(node); + case SyntaxKind.OptionalType: + return emitOptionalType(node); case SyntaxKind.UnionType: return emitUnionType(node); case SyntaxKind.IntersectionType: @@ -695,8 +697,9 @@ namespace ts { return emitJSDocNonNullableType(node as JSDocNonNullableType); case SyntaxKind.JSDocOptionalType: return emitJSDocOptionalType(node as JSDocOptionalType); + case SyntaxKind.RestType: case SyntaxKind.JSDocVariadicType: - return emitJSDocVariadicType(node as JSDocVariadicType); + return emitRestOrJSDocVariadicType(node as RestTypeNode | JSDocVariadicType); // Binding patterns case SyntaxKind.ObjectBindingPattern: @@ -1304,7 +1307,7 @@ namespace ts { writePunctuation("]"); } - function emitJSDocVariadicType(node: JSDocVariadicType) { + function emitRestOrJSDocVariadicType(node: RestTypeNode | JSDocVariadicType) { write("..."); emit(node.type); } @@ -1315,6 +1318,11 @@ namespace ts { writePunctuation("]"); } + function emitOptionalType(node: OptionalTypeNode) { + emit(node.type); + write("?"); + } + function emitUnionType(node: UnionTypeNode) { emitList(node, node.types, ListFormat.UnionTypeConstituents); } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 7b8a50ef603ca..b8b77193ed067 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -745,12 +745,36 @@ namespace ts { return node; } - export function updateTypleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray) { + export function updateTupleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray) { return node.elementTypes !== elementTypes ? updateNode(createTupleTypeNode(elementTypes), node) : node; } + export function createOptionalTypeNode(type: TypeNode) { + const node = createSynthesizedNode(SyntaxKind.OptionalType) as OptionalTypeNode; + node.type = parenthesizeArrayTypeMember(type); + return node; + } + + export function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode { + return node.type !== type + ? updateNode(createOptionalTypeNode(type), node) + : node; + } + + export function createRestTypeNode(type: TypeNode) { + const node = createSynthesizedNode(SyntaxKind.RestType) as RestTypeNode; + node.type = type; + return node; + } + + export function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode { + return node.type !== type + ? updateNode(createRestTypeNode(type), node) + : node; + } + export function createUnionTypeNode(types: ReadonlyArray): UnionTypeNode { return createUnionOrIntersectionTypeNode(SyntaxKind.UnionType, types); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ea0ec323798bc..f2b392f1d79ea 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -445,19 +445,17 @@ namespace ts { case SyntaxKind.JsxClosingElement: return visitNode(cbNode, (node).tagName); + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: case SyntaxKind.JSDocTypeExpression: - return visitNode(cbNode, (node).type); case SyntaxKind.JSDocNonNullableType: - return visitNode(cbNode, (node).type); case SyntaxKind.JSDocNullableType: - return visitNode(cbNode, (node).type); case SyntaxKind.JSDocOptionalType: - return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocVariadicType: + return visitNode(cbNode, (node).type); case SyntaxKind.JSDocFunctionType: return visitNodes(cbNode, cbNodes, (node).parameters) || visitNode(cbNode, (node).type); - case SyntaxKind.JSDocVariadicType: - return visitNode(cbNode, (node).type); case SyntaxKind.JSDocComment: return visitNodes(cbNode, cbNodes, (node).tags); case SyntaxKind.JSDocParameterTag: @@ -2293,7 +2291,7 @@ namespace ts { function parseJSDocAllType(postFixEquals: boolean): JSDocAllType | JSDocOptionalType { const result = createNode(SyntaxKind.JSDocAllType) as JSDocAllType; if (postFixEquals) { - return createJSDocPostfixType(SyntaxKind.JSDocOptionalType, result) as JSDocOptionalType; + return createPostfixType(SyntaxKind.JSDocOptionalType, result) as JSDocOptionalType; } else { nextToken(); @@ -2371,7 +2369,7 @@ namespace ts { type = finishNode(variadic); } if (token() === SyntaxKind.EqualsToken) { - return createJSDocPostfixType(SyntaxKind.JSDocOptionalType, type); + return createPostfixType(SyntaxKind.JSDocOptionalType, type); } return type; } @@ -2779,9 +2777,23 @@ namespace ts { return finishNode(node); } + function parseTupleElementType() { + const pos = getNodePos(); + if (parseOptional(SyntaxKind.DotDotDotToken)) { + const node = createNode(SyntaxKind.RestType, pos); + node.type = parseType(); + return finishNode(node); + } + const type = parseType(); + if (!(contextFlags & NodeFlags.JSDoc) && type.kind === SyntaxKind.JSDocNullableType && type.pos === (type).type.pos) { + type.kind = SyntaxKind.OptionalType; + } + return type; + } + function parseTupleType(): TupleTypeNode { const node = createNode(SyntaxKind.TupleType); - node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); + node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseTupleElementType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); return finishNode(node); } @@ -2964,14 +2976,14 @@ namespace ts { while (!scanner.hasPrecedingLineBreak()) { switch (token()) { case SyntaxKind.ExclamationToken: - type = createJSDocPostfixType(SyntaxKind.JSDocNonNullableType, type); + type = createPostfixType(SyntaxKind.JSDocNonNullableType, type); break; case SyntaxKind.QuestionToken: // If not in JSDoc and next token is start of a type we have a conditional type if (!(contextFlags & NodeFlags.JSDoc) && lookAhead(nextTokenIsStartOfType)) { return type; } - type = createJSDocPostfixType(SyntaxKind.JSDocNullableType, type); + type = createPostfixType(SyntaxKind.JSDocNullableType, type); break; case SyntaxKind.OpenBracketToken: parseExpected(SyntaxKind.OpenBracketToken); @@ -2996,9 +3008,9 @@ namespace ts { return type; } - function createJSDocPostfixType(kind: SyntaxKind, type: TypeNode) { + function createPostfixType(kind: SyntaxKind, type: TypeNode) { nextToken(); - const postfix = createNode(kind, type.pos) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType; + const postfix = createNode(kind, type.pos) as OptionalTypeNode | JSDocOptionalType | JSDocNonNullableType | JSDocNullableType; postfix.type = type; return finishNode(postfix); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 4712be940fe68..1e0da152764a0 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -380,6 +380,8 @@ namespace ts { case SyntaxKind.ArrayType: case SyntaxKind.TupleType: + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: case SyntaxKind.TypeLiteral: case SyntaxKind.TypePredicate: case SyntaxKind.TypeParameter: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9a776ea09723d..5b352ddde1e5e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -225,6 +225,8 @@ namespace ts { TypeLiteral, ArrayType, TupleType, + OptionalType, + RestType, UnionType, IntersectionType, ConditionalType, @@ -269,6 +271,7 @@ namespace ts { AsExpression, NonNullExpression, MetaProperty, + SyntheticExpression, // Misc TemplateSpan, @@ -1101,6 +1104,16 @@ namespace ts { elementTypes: NodeArray; } + export interface OptionalTypeNode extends TypeNode { + kind: SyntaxKind.OptionalType; + type: TypeNode; + } + + export interface RestTypeNode extends TypeNode { + kind: SyntaxKind.RestType; + type: TypeNode; + } + export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; export interface UnionTypeNode extends TypeNode { @@ -1288,6 +1301,12 @@ namespace ts { expression?: Expression; } + export interface SyntheticExpression extends Expression { + kind: SyntaxKind.SyntheticExpression; + isSpread: boolean; + type: Type; + } + // see: https://tc39.github.io/ecma262/#prod-ExponentiationExpression export type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken @@ -3520,14 +3539,15 @@ namespace ts { ContainsPrivate = 1 << 8, // Synthetic property with private constituent(s) ContainsStatic = 1 << 9, // Synthetic property with static constituent(s) Late = 1 << 10, // Late-bound symbol for a computed property with a dynamic name - ReverseMapped = 1 << 11, // property of reverse-inferred homomorphic mapped type. + ReverseMapped = 1 << 11, // Property of reverse-inferred homomorphic mapped type + OptionalParameter = 1 << 12, // Optional parameter + RestParameter = 1 << 13, // Rest parameter Synthetic = SyntheticProperty | SyntheticMethod } /* @internal */ export interface TransientSymbol extends Symbol, SymbolLinks { checkFlags: CheckFlags; - isRestParameter?: boolean; } /* @internal */ @@ -3856,6 +3876,16 @@ namespace ts { variances?: Variance[]; // Variance of each type parameter } + export interface TupleType extends GenericType { + minLength: number; + hasRestElement: boolean; + associatedNames?: __String[]; + } + + export interface TupleTypeReference extends TypeReference { + target: TupleType; + } + export interface UnionOrIntersectionType extends Type { types: Type[]; // Constituent types /* @internal */ diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index cda3158afeb2c..886d3be337a12 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -372,9 +372,17 @@ namespace ts { visitNode((node).elementType, visitor, isTypeNode)); case SyntaxKind.TupleType: - return updateTypleTypeNode((node), + return updateTupleTypeNode((node), nodesVisitor((node).elementTypes, visitor, isTypeNode)); + case SyntaxKind.OptionalType: + return updateOptionalTypeNode((node), + visitNode((node).type, visitor, isTypeNode)); + + case SyntaxKind.RestType: + return updateRestTypeNode((node), + visitNode((node).type, visitor, isTypeNode)); + case SyntaxKind.UnionType: return updateUnionTypeNode(node, nodesVisitor((node).types, visitor, isTypeNode)); diff --git a/tests/baselines/reference/TupleType3.errors.txt b/tests/baselines/reference/TupleType3.errors.txt deleted file mode 100644 index a7f5b1173257d..0000000000000 --- a/tests/baselines/reference/TupleType3.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/TupleTypes/TupleType3.ts(1,8): error TS1122: A tuple type element list cannot be empty. - - -==== tests/cases/conformance/parser/ecmascript5/TupleTypes/TupleType3.ts (1 errors) ==== - var v: [] - ~~ -!!! error TS1122: A tuple type element list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/anyIndexedAccessArrayNoException.errors.txt b/tests/baselines/reference/anyIndexedAccessArrayNoException.errors.txt index 01c5bd6b2e2c0..e207468122bc0 100644 --- a/tests/baselines/reference/anyIndexedAccessArrayNoException.errors.txt +++ b/tests/baselines/reference/anyIndexedAccessArrayNoException.errors.txt @@ -1,11 +1,8 @@ -tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS1122: A tuple type element list cannot be empty. tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS2538: Type '[]' cannot be used as an index type. -==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (2 errors) ==== +==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (1 errors) ==== var x: any[[]]; ~~ -!!! error TS1122: A tuple type element list cannot be empty. - ~~ !!! error TS2538: Type '[]' cannot be used as an index type. \ No newline at end of file diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2bd0930e4db6c..acf6047e7993c 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -747,144 +747,147 @@ declare namespace ts { TypeLiteral = 166, ArrayType = 167, TupleType = 168, - UnionType = 169, - IntersectionType = 170, - ConditionalType = 171, - InferType = 172, - ParenthesizedType = 173, - ThisType = 174, - TypeOperator = 175, - IndexedAccessType = 176, - MappedType = 177, - LiteralType = 178, - ImportType = 179, - ObjectBindingPattern = 180, - ArrayBindingPattern = 181, - BindingElement = 182, - ArrayLiteralExpression = 183, - ObjectLiteralExpression = 184, - PropertyAccessExpression = 185, - ElementAccessExpression = 186, - CallExpression = 187, - NewExpression = 188, - TaggedTemplateExpression = 189, - TypeAssertionExpression = 190, - ParenthesizedExpression = 191, - FunctionExpression = 192, - ArrowFunction = 193, - DeleteExpression = 194, - TypeOfExpression = 195, - VoidExpression = 196, - AwaitExpression = 197, - PrefixUnaryExpression = 198, - PostfixUnaryExpression = 199, - BinaryExpression = 200, - ConditionalExpression = 201, - TemplateExpression = 202, - YieldExpression = 203, - SpreadElement = 204, - ClassExpression = 205, - OmittedExpression = 206, - ExpressionWithTypeArguments = 207, - AsExpression = 208, - NonNullExpression = 209, - MetaProperty = 210, - TemplateSpan = 211, - SemicolonClassElement = 212, - Block = 213, - VariableStatement = 214, - EmptyStatement = 215, - ExpressionStatement = 216, - IfStatement = 217, - DoStatement = 218, - WhileStatement = 219, - ForStatement = 220, - ForInStatement = 221, - ForOfStatement = 222, - ContinueStatement = 223, - BreakStatement = 224, - ReturnStatement = 225, - WithStatement = 226, - SwitchStatement = 227, - LabeledStatement = 228, - ThrowStatement = 229, - TryStatement = 230, - DebuggerStatement = 231, - VariableDeclaration = 232, - VariableDeclarationList = 233, - FunctionDeclaration = 234, - ClassDeclaration = 235, - InterfaceDeclaration = 236, - TypeAliasDeclaration = 237, - EnumDeclaration = 238, - ModuleDeclaration = 239, - ModuleBlock = 240, - CaseBlock = 241, - NamespaceExportDeclaration = 242, - ImportEqualsDeclaration = 243, - ImportDeclaration = 244, - ImportClause = 245, - NamespaceImport = 246, - NamedImports = 247, - ImportSpecifier = 248, - ExportAssignment = 249, - ExportDeclaration = 250, - NamedExports = 251, - ExportSpecifier = 252, - MissingDeclaration = 253, - ExternalModuleReference = 254, - JsxElement = 255, - JsxSelfClosingElement = 256, - JsxOpeningElement = 257, - JsxClosingElement = 258, - JsxFragment = 259, - JsxOpeningFragment = 260, - JsxClosingFragment = 261, - JsxAttribute = 262, - JsxAttributes = 263, - JsxSpreadAttribute = 264, - JsxExpression = 265, - CaseClause = 266, - DefaultClause = 267, - HeritageClause = 268, - CatchClause = 269, - PropertyAssignment = 270, - ShorthandPropertyAssignment = 271, - SpreadAssignment = 272, - EnumMember = 273, - SourceFile = 274, - Bundle = 275, - UnparsedSource = 276, - InputFiles = 277, - JSDocTypeExpression = 278, - JSDocAllType = 279, - JSDocUnknownType = 280, - JSDocNullableType = 281, - JSDocNonNullableType = 282, - JSDocOptionalType = 283, - JSDocFunctionType = 284, - JSDocVariadicType = 285, - JSDocComment = 286, - JSDocTypeLiteral = 287, - JSDocSignature = 288, - JSDocTag = 289, - JSDocAugmentsTag = 290, - JSDocClassTag = 291, - JSDocCallbackTag = 292, - JSDocParameterTag = 293, - JSDocReturnTag = 294, - JSDocThisTag = 295, - JSDocTypeTag = 296, - JSDocTemplateTag = 297, - JSDocTypedefTag = 298, - JSDocPropertyTag = 299, - SyntaxList = 300, - NotEmittedStatement = 301, - PartiallyEmittedExpression = 302, - CommaListExpression = 303, - MergeDeclarationMarker = 304, - EndOfDeclarationMarker = 305, - Count = 306, + OptionalType = 169, + RestType = 170, + UnionType = 171, + IntersectionType = 172, + ConditionalType = 173, + InferType = 174, + ParenthesizedType = 175, + ThisType = 176, + TypeOperator = 177, + IndexedAccessType = 178, + MappedType = 179, + LiteralType = 180, + ImportType = 181, + ObjectBindingPattern = 182, + ArrayBindingPattern = 183, + BindingElement = 184, + ArrayLiteralExpression = 185, + ObjectLiteralExpression = 186, + PropertyAccessExpression = 187, + ElementAccessExpression = 188, + CallExpression = 189, + NewExpression = 190, + TaggedTemplateExpression = 191, + TypeAssertionExpression = 192, + ParenthesizedExpression = 193, + FunctionExpression = 194, + ArrowFunction = 195, + DeleteExpression = 196, + TypeOfExpression = 197, + VoidExpression = 198, + AwaitExpression = 199, + PrefixUnaryExpression = 200, + PostfixUnaryExpression = 201, + BinaryExpression = 202, + ConditionalExpression = 203, + TemplateExpression = 204, + YieldExpression = 205, + SpreadElement = 206, + ClassExpression = 207, + OmittedExpression = 208, + ExpressionWithTypeArguments = 209, + AsExpression = 210, + NonNullExpression = 211, + MetaProperty = 212, + SyntheticExpression = 213, + TemplateSpan = 214, + SemicolonClassElement = 215, + Block = 216, + VariableStatement = 217, + EmptyStatement = 218, + ExpressionStatement = 219, + IfStatement = 220, + DoStatement = 221, + WhileStatement = 222, + ForStatement = 223, + ForInStatement = 224, + ForOfStatement = 225, + ContinueStatement = 226, + BreakStatement = 227, + ReturnStatement = 228, + WithStatement = 229, + SwitchStatement = 230, + LabeledStatement = 231, + ThrowStatement = 232, + TryStatement = 233, + DebuggerStatement = 234, + VariableDeclaration = 235, + VariableDeclarationList = 236, + FunctionDeclaration = 237, + ClassDeclaration = 238, + InterfaceDeclaration = 239, + TypeAliasDeclaration = 240, + EnumDeclaration = 241, + ModuleDeclaration = 242, + ModuleBlock = 243, + CaseBlock = 244, + NamespaceExportDeclaration = 245, + ImportEqualsDeclaration = 246, + ImportDeclaration = 247, + ImportClause = 248, + NamespaceImport = 249, + NamedImports = 250, + ImportSpecifier = 251, + ExportAssignment = 252, + ExportDeclaration = 253, + NamedExports = 254, + ExportSpecifier = 255, + MissingDeclaration = 256, + ExternalModuleReference = 257, + JsxElement = 258, + JsxSelfClosingElement = 259, + JsxOpeningElement = 260, + JsxClosingElement = 261, + JsxFragment = 262, + JsxOpeningFragment = 263, + JsxClosingFragment = 264, + JsxAttribute = 265, + JsxAttributes = 266, + JsxSpreadAttribute = 267, + JsxExpression = 268, + CaseClause = 269, + DefaultClause = 270, + HeritageClause = 271, + CatchClause = 272, + PropertyAssignment = 273, + ShorthandPropertyAssignment = 274, + SpreadAssignment = 275, + EnumMember = 276, + SourceFile = 277, + Bundle = 278, + UnparsedSource = 279, + InputFiles = 280, + JSDocTypeExpression = 281, + JSDocAllType = 282, + JSDocUnknownType = 283, + JSDocNullableType = 284, + JSDocNonNullableType = 285, + JSDocOptionalType = 286, + JSDocFunctionType = 287, + JSDocVariadicType = 288, + JSDocComment = 289, + JSDocTypeLiteral = 290, + JSDocSignature = 291, + JSDocTag = 292, + JSDocAugmentsTag = 293, + JSDocClassTag = 294, + JSDocCallbackTag = 295, + JSDocParameterTag = 296, + JSDocReturnTag = 297, + JSDocThisTag = 298, + JSDocTypeTag = 299, + JSDocTemplateTag = 300, + JSDocTypedefTag = 301, + JSDocPropertyTag = 302, + SyntaxList = 303, + NotEmittedStatement = 304, + PartiallyEmittedExpression = 305, + CommaListExpression = 306, + MergeDeclarationMarker = 307, + EndOfDeclarationMarker = 308, + Count = 309, FirstAssignment = 58, LastAssignment = 70, FirstCompoundAssignment = 59, @@ -896,7 +899,7 @@ declare namespace ts { FirstFutureReservedWord = 108, LastFutureReservedWord = 116, FirstTypeNode = 161, - LastTypeNode = 179, + LastTypeNode = 181, FirstPunctuation = 17, LastPunctuation = 70, FirstToken = 0, @@ -910,10 +913,10 @@ declare namespace ts { FirstBinaryOperator = 27, LastBinaryOperator = 70, FirstNode = 146, - FirstJSDocNode = 278, - LastJSDocNode = 299, - FirstJSDocTagNode = 289, - LastJSDocTagNode = 299, + FirstJSDocNode = 281, + LastJSDocNode = 302, + FirstJSDocTagNode = 292, + LastJSDocTagNode = 302, FirstContextualKeyword = 117, LastContextualKeyword = 145 } @@ -1336,6 +1339,14 @@ declare namespace ts { kind: SyntaxKind.TupleType; elementTypes: NodeArray; } + interface OptionalTypeNode extends TypeNode { + kind: SyntaxKind.OptionalType; + type: TypeNode; + } + interface RestTypeNode extends TypeNode { + kind: SyntaxKind.RestType; + type: TypeNode; + } type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; interface UnionTypeNode extends TypeNode { kind: SyntaxKind.UnionType; @@ -1466,6 +1477,11 @@ declare namespace ts { asteriskToken?: AsteriskToken; expression?: Expression; } + interface SyntheticExpression extends Expression { + kind: SyntaxKind.SyntheticExpression; + isSpread: boolean; + type: Type; + } type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; type MultiplicativeOperatorOrHigher = ExponentiationOperator | MultiplicativeOperator; @@ -3074,11 +3090,12 @@ declare namespace ts { ContainsStatic = 512, Late = 1024, ReverseMapped = 2048, + OptionalParameter = 4096, + RestParameter = 8192, Synthetic = 6 } interface TransientSymbol extends Symbol, SymbolLinks { checkFlags: CheckFlags; - isRestParameter?: boolean; } interface ReverseMappedSymbol extends TransientSymbol { propertyType: Type; @@ -3338,6 +3355,14 @@ declare namespace ts { instantiations: Map; variances?: Variance[]; } + interface TupleType extends GenericType { + minLength: number; + hasRestElement: boolean; + associatedNames?: __String[]; + } + interface TupleTypeReference extends TypeReference { + target: TupleType; + } interface UnionOrIntersectionType extends Type { types: Type[]; propertyCache: SymbolTable; @@ -4905,7 +4930,6 @@ declare namespace ts { An_object_literal_cannot_have_property_and_accessor_with_the_same_name: DiagnosticMessage; An_export_assignment_cannot_have_modifiers: DiagnosticMessage; Octal_literals_are_not_allowed_in_strict_mode: DiagnosticMessage; - A_tuple_type_element_list_cannot_be_empty: DiagnosticMessage; Variable_declaration_list_cannot_be_empty: DiagnosticMessage; Digit_expected: DiagnosticMessage; Hexadecimal_digit_expected: DiagnosticMessage; @@ -5025,6 +5049,8 @@ declare namespace ts { _0_tag_cannot_be_used_independently_as_a_top_level_JSDoc_tag: DiagnosticMessage; A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal: DiagnosticMessage; A_definite_assignment_assertion_is_not_permitted_in_this_context: DiagnosticMessage; + A_rest_element_must_be_last_in_a_tuple_type: DiagnosticMessage; + A_required_element_cannot_follow_an_optional_element: DiagnosticMessage; with_statements_are_not_allowed_in_an_async_function_block: DiagnosticMessage; await_expression_is_only_allowed_within_an_async_function: DiagnosticMessage; can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: DiagnosticMessage; @@ -5321,6 +5347,9 @@ declare namespace ts { Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: DiagnosticMessage; Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: DiagnosticMessage; Object_is_of_type_unknown: DiagnosticMessage; + Rest_signatures_are_incompatible: DiagnosticMessage; + Property_0_is_incompatible_with_rest_element_type: DiagnosticMessage; + A_rest_element_type_must_be_an_array_type: DiagnosticMessage; JSX_element_attributes_type_0_may_not_be_a_union_type: DiagnosticMessage; The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: DiagnosticMessage; JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: DiagnosticMessage; @@ -7776,7 +7805,11 @@ declare namespace ts { function createArrayTypeNode(elementType: TypeNode): ArrayTypeNode; function updateArrayTypeNode(node: ArrayTypeNode, elementType: TypeNode): ArrayTypeNode; function createTupleTypeNode(elementTypes: ReadonlyArray): TupleTypeNode; - function updateTypleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray): TupleTypeNode; + function updateTupleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray): TupleTypeNode; + function createOptionalTypeNode(type: TypeNode): OptionalTypeNode; + function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode; + function createRestTypeNode(type: TypeNode): RestTypeNode; + function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode; function createUnionTypeNode(types: ReadonlyArray): UnionTypeNode; function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode; function createIntersectionTypeNode(types: ReadonlyArray): IntersectionTypeNode; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2195a9d7d76b5..273e0cad00e45 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -226,144 +226,147 @@ declare namespace ts { TypeLiteral = 166, ArrayType = 167, TupleType = 168, - UnionType = 169, - IntersectionType = 170, - ConditionalType = 171, - InferType = 172, - ParenthesizedType = 173, - ThisType = 174, - TypeOperator = 175, - IndexedAccessType = 176, - MappedType = 177, - LiteralType = 178, - ImportType = 179, - ObjectBindingPattern = 180, - ArrayBindingPattern = 181, - BindingElement = 182, - ArrayLiteralExpression = 183, - ObjectLiteralExpression = 184, - PropertyAccessExpression = 185, - ElementAccessExpression = 186, - CallExpression = 187, - NewExpression = 188, - TaggedTemplateExpression = 189, - TypeAssertionExpression = 190, - ParenthesizedExpression = 191, - FunctionExpression = 192, - ArrowFunction = 193, - DeleteExpression = 194, - TypeOfExpression = 195, - VoidExpression = 196, - AwaitExpression = 197, - PrefixUnaryExpression = 198, - PostfixUnaryExpression = 199, - BinaryExpression = 200, - ConditionalExpression = 201, - TemplateExpression = 202, - YieldExpression = 203, - SpreadElement = 204, - ClassExpression = 205, - OmittedExpression = 206, - ExpressionWithTypeArguments = 207, - AsExpression = 208, - NonNullExpression = 209, - MetaProperty = 210, - TemplateSpan = 211, - SemicolonClassElement = 212, - Block = 213, - VariableStatement = 214, - EmptyStatement = 215, - ExpressionStatement = 216, - IfStatement = 217, - DoStatement = 218, - WhileStatement = 219, - ForStatement = 220, - ForInStatement = 221, - ForOfStatement = 222, - ContinueStatement = 223, - BreakStatement = 224, - ReturnStatement = 225, - WithStatement = 226, - SwitchStatement = 227, - LabeledStatement = 228, - ThrowStatement = 229, - TryStatement = 230, - DebuggerStatement = 231, - VariableDeclaration = 232, - VariableDeclarationList = 233, - FunctionDeclaration = 234, - ClassDeclaration = 235, - InterfaceDeclaration = 236, - TypeAliasDeclaration = 237, - EnumDeclaration = 238, - ModuleDeclaration = 239, - ModuleBlock = 240, - CaseBlock = 241, - NamespaceExportDeclaration = 242, - ImportEqualsDeclaration = 243, - ImportDeclaration = 244, - ImportClause = 245, - NamespaceImport = 246, - NamedImports = 247, - ImportSpecifier = 248, - ExportAssignment = 249, - ExportDeclaration = 250, - NamedExports = 251, - ExportSpecifier = 252, - MissingDeclaration = 253, - ExternalModuleReference = 254, - JsxElement = 255, - JsxSelfClosingElement = 256, - JsxOpeningElement = 257, - JsxClosingElement = 258, - JsxFragment = 259, - JsxOpeningFragment = 260, - JsxClosingFragment = 261, - JsxAttribute = 262, - JsxAttributes = 263, - JsxSpreadAttribute = 264, - JsxExpression = 265, - CaseClause = 266, - DefaultClause = 267, - HeritageClause = 268, - CatchClause = 269, - PropertyAssignment = 270, - ShorthandPropertyAssignment = 271, - SpreadAssignment = 272, - EnumMember = 273, - SourceFile = 274, - Bundle = 275, - UnparsedSource = 276, - InputFiles = 277, - JSDocTypeExpression = 278, - JSDocAllType = 279, - JSDocUnknownType = 280, - JSDocNullableType = 281, - JSDocNonNullableType = 282, - JSDocOptionalType = 283, - JSDocFunctionType = 284, - JSDocVariadicType = 285, - JSDocComment = 286, - JSDocTypeLiteral = 287, - JSDocSignature = 288, - JSDocTag = 289, - JSDocAugmentsTag = 290, - JSDocClassTag = 291, - JSDocCallbackTag = 292, - JSDocParameterTag = 293, - JSDocReturnTag = 294, - JSDocThisTag = 295, - JSDocTypeTag = 296, - JSDocTemplateTag = 297, - JSDocTypedefTag = 298, - JSDocPropertyTag = 299, - SyntaxList = 300, - NotEmittedStatement = 301, - PartiallyEmittedExpression = 302, - CommaListExpression = 303, - MergeDeclarationMarker = 304, - EndOfDeclarationMarker = 305, - Count = 306, + OptionalType = 169, + RestType = 170, + UnionType = 171, + IntersectionType = 172, + ConditionalType = 173, + InferType = 174, + ParenthesizedType = 175, + ThisType = 176, + TypeOperator = 177, + IndexedAccessType = 178, + MappedType = 179, + LiteralType = 180, + ImportType = 181, + ObjectBindingPattern = 182, + ArrayBindingPattern = 183, + BindingElement = 184, + ArrayLiteralExpression = 185, + ObjectLiteralExpression = 186, + PropertyAccessExpression = 187, + ElementAccessExpression = 188, + CallExpression = 189, + NewExpression = 190, + TaggedTemplateExpression = 191, + TypeAssertionExpression = 192, + ParenthesizedExpression = 193, + FunctionExpression = 194, + ArrowFunction = 195, + DeleteExpression = 196, + TypeOfExpression = 197, + VoidExpression = 198, + AwaitExpression = 199, + PrefixUnaryExpression = 200, + PostfixUnaryExpression = 201, + BinaryExpression = 202, + ConditionalExpression = 203, + TemplateExpression = 204, + YieldExpression = 205, + SpreadElement = 206, + ClassExpression = 207, + OmittedExpression = 208, + ExpressionWithTypeArguments = 209, + AsExpression = 210, + NonNullExpression = 211, + MetaProperty = 212, + SyntheticExpression = 213, + TemplateSpan = 214, + SemicolonClassElement = 215, + Block = 216, + VariableStatement = 217, + EmptyStatement = 218, + ExpressionStatement = 219, + IfStatement = 220, + DoStatement = 221, + WhileStatement = 222, + ForStatement = 223, + ForInStatement = 224, + ForOfStatement = 225, + ContinueStatement = 226, + BreakStatement = 227, + ReturnStatement = 228, + WithStatement = 229, + SwitchStatement = 230, + LabeledStatement = 231, + ThrowStatement = 232, + TryStatement = 233, + DebuggerStatement = 234, + VariableDeclaration = 235, + VariableDeclarationList = 236, + FunctionDeclaration = 237, + ClassDeclaration = 238, + InterfaceDeclaration = 239, + TypeAliasDeclaration = 240, + EnumDeclaration = 241, + ModuleDeclaration = 242, + ModuleBlock = 243, + CaseBlock = 244, + NamespaceExportDeclaration = 245, + ImportEqualsDeclaration = 246, + ImportDeclaration = 247, + ImportClause = 248, + NamespaceImport = 249, + NamedImports = 250, + ImportSpecifier = 251, + ExportAssignment = 252, + ExportDeclaration = 253, + NamedExports = 254, + ExportSpecifier = 255, + MissingDeclaration = 256, + ExternalModuleReference = 257, + JsxElement = 258, + JsxSelfClosingElement = 259, + JsxOpeningElement = 260, + JsxClosingElement = 261, + JsxFragment = 262, + JsxOpeningFragment = 263, + JsxClosingFragment = 264, + JsxAttribute = 265, + JsxAttributes = 266, + JsxSpreadAttribute = 267, + JsxExpression = 268, + CaseClause = 269, + DefaultClause = 270, + HeritageClause = 271, + CatchClause = 272, + PropertyAssignment = 273, + ShorthandPropertyAssignment = 274, + SpreadAssignment = 275, + EnumMember = 276, + SourceFile = 277, + Bundle = 278, + UnparsedSource = 279, + InputFiles = 280, + JSDocTypeExpression = 281, + JSDocAllType = 282, + JSDocUnknownType = 283, + JSDocNullableType = 284, + JSDocNonNullableType = 285, + JSDocOptionalType = 286, + JSDocFunctionType = 287, + JSDocVariadicType = 288, + JSDocComment = 289, + JSDocTypeLiteral = 290, + JSDocSignature = 291, + JSDocTag = 292, + JSDocAugmentsTag = 293, + JSDocClassTag = 294, + JSDocCallbackTag = 295, + JSDocParameterTag = 296, + JSDocReturnTag = 297, + JSDocThisTag = 298, + JSDocTypeTag = 299, + JSDocTemplateTag = 300, + JSDocTypedefTag = 301, + JSDocPropertyTag = 302, + SyntaxList = 303, + NotEmittedStatement = 304, + PartiallyEmittedExpression = 305, + CommaListExpression = 306, + MergeDeclarationMarker = 307, + EndOfDeclarationMarker = 308, + Count = 309, FirstAssignment = 58, LastAssignment = 70, FirstCompoundAssignment = 59, @@ -375,7 +378,7 @@ declare namespace ts { FirstFutureReservedWord = 108, LastFutureReservedWord = 116, FirstTypeNode = 161, - LastTypeNode = 179, + LastTypeNode = 181, FirstPunctuation = 17, LastPunctuation = 70, FirstToken = 0, @@ -389,10 +392,10 @@ declare namespace ts { FirstBinaryOperator = 27, LastBinaryOperator = 70, FirstNode = 146, - FirstJSDocNode = 278, - LastJSDocNode = 299, - FirstJSDocTagNode = 289, - LastJSDocTagNode = 299 + FirstJSDocNode = 281, + LastJSDocNode = 302, + FirstJSDocTagNode = 292, + LastJSDocTagNode = 302 } enum NodeFlags { None = 0, @@ -751,6 +754,14 @@ declare namespace ts { kind: SyntaxKind.TupleType; elementTypes: NodeArray; } + interface OptionalTypeNode extends TypeNode { + kind: SyntaxKind.OptionalType; + type: TypeNode; + } + interface RestTypeNode extends TypeNode { + kind: SyntaxKind.RestType; + type: TypeNode; + } type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; interface UnionTypeNode extends TypeNode { kind: SyntaxKind.UnionType; @@ -875,6 +886,11 @@ declare namespace ts { asteriskToken?: AsteriskToken; expression?: Expression; } + interface SyntheticExpression extends Expression { + kind: SyntaxKind.SyntheticExpression; + isSpread: boolean; + type: Type; + } type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; type MultiplicativeOperatorOrHigher = ExponentiationOperator | MultiplicativeOperator; @@ -2267,6 +2283,14 @@ declare namespace ts { } interface GenericType extends InterfaceType, TypeReference { } + interface TupleType extends GenericType { + minLength: number; + hasRestElement: boolean; + associatedNames?: __String[]; + } + interface TupleTypeReference extends TypeReference { + target: TupleType; + } interface UnionOrIntersectionType extends Type { types: Type[]; } @@ -3694,7 +3718,11 @@ declare namespace ts { function createArrayTypeNode(elementType: TypeNode): ArrayTypeNode; function updateArrayTypeNode(node: ArrayTypeNode, elementType: TypeNode): ArrayTypeNode; function createTupleTypeNode(elementTypes: ReadonlyArray): TupleTypeNode; - function updateTypleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray): TupleTypeNode; + function updateTupleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray): TupleTypeNode; + function createOptionalTypeNode(type: TypeNode): OptionalTypeNode; + function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode; + function createRestTypeNode(type: TypeNode): RestTypeNode; + function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode; function createUnionTypeNode(types: ReadonlyArray): UnionTypeNode; function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode; function createIntersectionTypeNode(types: ReadonlyArray): IntersectionTypeNode; diff --git a/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt b/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt index c1bac0fb1ffbc..87c3a6d0b37a3 100644 --- a/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt +++ b/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt @@ -1,6 +1,8 @@ tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(16,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. Property '0' is missing in type '(string | number | boolean)[]'. -tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(17,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. +tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(17,5): error TS2345: Argument of type '[string, number, true, ...(string | number | boolean)[]]' is not assignable to parameter of type '[string, number, boolean]'. + Types of property 'length' are incompatible. + Type 'number' is not assignable to type '3'. tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(18,5): error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'. Types of property 'x' are incompatible. Type '(string | number)[]' is not assignable to type '[any, any]'. @@ -29,7 +31,9 @@ tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextua !!! error TS2345: Property '0' is missing in type '(string | number | boolean)[]'. baz(["string", 1, true, ...array]); // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. +!!! error TS2345: Argument of type '[string, number, true, ...(string | number | boolean)[]]' is not assignable to parameter of type '[string, number, boolean]'. +!!! error TS2345: Types of property 'length' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '3'. foo(o); // Error because x has an array type namely (string|number)[] ~ !!! error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'. diff --git a/tests/baselines/reference/argumentExpressionContextualTyping.types b/tests/baselines/reference/argumentExpressionContextualTyping.types index 9a7d3f97d5b74..46ef3a3857027 100644 --- a/tests/baselines/reference/argumentExpressionContextualTyping.types +++ b/tests/baselines/reference/argumentExpressionContextualTyping.types @@ -11,7 +11,7 @@ function foo({x: [a, b], y: {c, d, e}}) { } >e : any function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { } ->bar : ({ x: [a, b], y: { c, d, e } }: { x: [any, number]; y: { c: any; d: any; e?: { f: number; }; }; }) => void +>bar : ({ x: [a, b], y: { c, d, e } }: { x: [any, number?]; y: { c: any; d: any; e?: { f: number; }; }; }) => void >x : any >a : any >b : number diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt index 8cb36b113a754..e2d047ac711c1 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt @@ -7,8 +7,9 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'. Types of property 'length' are incompatible. Type '4' is not assignable to type '3'. -tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. - Property '0' is missing in type 'number[]'. +tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type '[number, number, number, ...number[]]' is not assignable to type '[number, number, number]'. + Types of property 'length' are incompatible. + Type 'number' is not assignable to type '3'. ==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (4 errors) ==== @@ -39,6 +40,7 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte var spr1 = [1, 2, 3, ...tup]; var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error ~~~~ -!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. -!!! error TS2322: Property '0' is missing in type 'number[]'. +!!! error TS2322: Type '[number, number, number, ...number[]]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Types of property 'length' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type '3'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.types b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.types index 5954448c984fb..3c1a9b6ba722b 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.types +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.types @@ -62,7 +62,7 @@ var spr1 = [1, 2, 3, ...tup]; var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error >spr2 : [number, number, number] ->[1, 2, 3, ...tup] : number[] +>[1, 2, 3, ...tup] : [number, number, number, ...number[]] >1 : 1 >2 : 2 >3 : 3 diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index a3a3b88bc4a8a..8ce34900b0a7b 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'. - Property '0' is missing in type 'undefined[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2322: Type '[]' is not assignable to type '[any, any, any]'. + Property '0' is missing in type '[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'. Type 'string' is not assignable to type 'boolean'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. @@ -30,8 +30,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error var a0: [any, any, any] = []; // Error ~~ -!!! error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'. -!!! error TS2322: Property '0' is missing in type 'undefined[]'. +!!! error TS2322: Type '[]' is not assignable to type '[any, any, any]'. +!!! error TS2322: Property '0' is missing in type '[]'. var a1: [boolean, string, number] = ["string", 1, true]; // Error ~~ !!! error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'. diff --git a/tests/baselines/reference/arrayLiterals3.types b/tests/baselines/reference/arrayLiterals3.types index 7d890f38fb4d8..bf3ff4cf4f640 100644 --- a/tests/baselines/reference/arrayLiterals3.types +++ b/tests/baselines/reference/arrayLiterals3.types @@ -10,7 +10,7 @@ var a0: [any, any, any] = []; // Error >a0 : [any, any, any] ->[] : undefined[] +>[] : [] var a1: [boolean, string, number] = ["string", 1, true]; // Error >a1 : [boolean, string, number] diff --git a/tests/baselines/reference/arrowFunctionExpressions.types b/tests/baselines/reference/arrowFunctionExpressions.types index 0de6c674d18dc..9eb9b09181369 100644 --- a/tests/baselines/reference/arrowFunctionExpressions.types +++ b/tests/baselines/reference/arrowFunctionExpressions.types @@ -71,14 +71,14 @@ var p3 = ([, a]) => { }; >a : any var p4 = ([, ...a]) => { }; ->p4 : ([, ...a]: any[]) => void ->([, ...a]) => { } : ([, ...a]: any[]) => void +>p4 : ([, ...a]: [any?, ...any[]]) => void +>([, ...a]) => { } : ([, ...a]: [any?, ...any[]]) => void > : undefined >a : any[] var p5 = ([a = 1]) => { }; ->p5 : ([a]: [number]) => void ->([a = 1]) => { } : ([a]: [number]) => void +>p5 : ([a]: [number?]) => void +>([a = 1]) => { } : ([a]: [number?]) => void >a : number >1 : 1 diff --git a/tests/baselines/reference/callWithSpread2.errors.txt b/tests/baselines/reference/callWithSpread2.errors.txt index 9028d37af0906..4333571ebf862 100644 --- a/tests/baselines/reference/callWithSpread2.errors.txt +++ b/tests/baselines/reference/callWithSpread2.errors.txt @@ -2,19 +2,16 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(22,1): erro tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(23,1): error TS2556: Expected 0 arguments, but got 1 or more. tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(26,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(27,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(27,5): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(28,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(29,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(29,13): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(30,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(31,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(31,11): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(32,1): error TS2556: Expected 1-3 arguments, but got 0 or more. tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(33,1): error TS2556: Expected 1-3 arguments, but got 0 or more. -tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(34,1): error TS2556: Expected 1-3 arguments, but got 0 or more. +tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(34,8): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. ==== tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts (11 errors) ==== @@ -53,24 +50,21 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(34,1): erro !!! error TS2345: Type 'string' is not assignable to type 'number'. all(...tuple) ~~~~~~~~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. -!!! error TS2345: Type 'string' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. prefix("b", ...mixed) ~~~~~~~~ !!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. prefix("c", ...tuple) ~~~~~~~~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. -!!! error TS2345: Type 'string' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. rest("e", ...mixed) ~~~~~~~~ !!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. rest("f", ...tuple) ~~~~~~~~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. -!!! error TS2345: Type 'string' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. prefix(...ns) // required parameters are required ~~~~~~~~~~~~~ !!! error TS2556: Expected 1-3 arguments, but got 0 or more. @@ -78,6 +72,6 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(34,1): erro ~~~~~~~~~~~~~~~~ !!! error TS2556: Expected 1-3 arguments, but got 0 or more. prefix(...tuple) - ~~~~~~~~~~~~~~~~ -!!! error TS2556: Expected 1-3 arguments, but got 0 or more. + ~~~~~~~~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js index b21c63203c894..63b90f5d41d72 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.js +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -14,5 +14,5 @@ function foo(_a) { //// [declarationEmitDestructuring3.d.ts] -declare function bar([x, z, ...w]: any[]): void; -declare function foo([x, ...y]?: (string | number | boolean)[]): void; +declare function bar([x, z, ...w]: [any, any, ...any[]]): void; +declare function foo([x, ...y]?: [number, string, boolean]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring3.types b/tests/baselines/reference/declarationEmitDestructuring3.types index 8e15071c9792f..537de8e1e7450 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -1,15 +1,15 @@ === tests/cases/compiler/declarationEmitDestructuring3.ts === function bar([x, z, ...w]) { } ->bar : ([x, z, ...w]: any[]) => void +>bar : ([x, z, ...w]: [any, any, ...any[]]) => void >x : any >z : any >w : any[] function foo([x, ...y] = [1, "string", true]) { } ->foo : ([x, ...y]?: (string | number | boolean)[]) => void ->x : string | number | boolean ->y : (string | number | boolean)[] ->[1, "string", true] : (string | number | boolean)[] +>foo : ([x, ...y]?: [number, string, boolean]) => void +>x : number +>y : (string | boolean)[] +>[1, "string", true] : [number, string, boolean] >1 : 1 >"string" : "string" >true : true diff --git a/tests/baselines/reference/declarationEmitDestructuring5.js b/tests/baselines/reference/declarationEmitDestructuring5.js index e5089bb209767..06a57a8ca2702 100644 --- a/tests/baselines/reference/declarationEmitDestructuring5.js +++ b/tests/baselines/reference/declarationEmitDestructuring5.js @@ -24,8 +24,8 @@ function bar2(_a) { //// [declarationEmitDestructuring5.d.ts] -declare function baz([, z, ,]: [any, any, any]): void; +declare function baz([, z, ,]: [any, any, any?]): void; declare function foo([, b,]: [any, any]): void; -declare function bar([z, , ,]: [any, any, any]): void; +declare function bar([z, , ,]: [any, any?, any?]): void; declare function bar1([z, , ,]?: [number, number, number, number, number]): void; -declare function bar2([, , z, , ,]: [any, any, any, any, any]): void; +declare function bar2([, , z, , ,]: [any, any, any, any?, any?]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring5.types b/tests/baselines/reference/declarationEmitDestructuring5.types index c0223a0f061dd..770779fdb2fc9 100644 --- a/tests/baselines/reference/declarationEmitDestructuring5.types +++ b/tests/baselines/reference/declarationEmitDestructuring5.types @@ -1,6 +1,6 @@ === tests/cases/compiler/declarationEmitDestructuring5.ts === function baz([, z, , ]) { } ->baz : ([, z, ,]: [any, any, any]) => void +>baz : ([, z, ,]: [any, any, any?]) => void > : undefined >z : any > : undefined @@ -11,7 +11,7 @@ function foo([, b, ]: [any, any]): void { } >b : any function bar([z, , , ]) { } ->bar : ([z, , ,]: [any, any, any]) => void +>bar : ([z, , ,]: [any, any?, any?]) => void >z : any > : undefined > : undefined @@ -29,7 +29,7 @@ function bar1([z, , , ] = [1, 3, 4, 6, 7]) { } >7 : 7 function bar2([,,z, , , ]) { } ->bar2 : ([, , z, , ,]: [any, any, any, any, any]) => void +>bar2 : ([, , z, , ,]: [any, any, any, any?, any?]) => void > : undefined > : undefined >z : any diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index 097cab978d5c3..37781e0a1aefb 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -23,7 +23,7 @@ var [a11, b11, c11] = []; >a11 : any >b11 : any >c11 : any ->[] : [undefined, undefined, undefined] +>[] : [undefined?, undefined?, undefined?] var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; >a2 : number diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js index 1bd07e7b974e8..f0438ba5a8a36 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -24,8 +24,8 @@ var _f = [1, "hello", true], x19 = _f[0], y19 = _f[1], z19 = _f[2], a13 = _f.sli declare var a5: number[]; declare var x14: number, a6: number[]; declare var x15: number, y15: number, a7: number[]; -declare var x16: number, y16: number, z16: number, a8: number[]; +declare var x16: number, y16: number, z16: number, a8: any[]; declare var a9: (string | number | boolean)[]; -declare var x17: string | number | boolean, a10: (string | number | boolean)[]; -declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; -declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; +declare var x17: number, a10: (string | boolean)[]; +declare var x18: number, y18: string, a12: boolean[]; +declare var x19: number, y19: string, z19: boolean, a13: any[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types index 0141b3f79e709..52c292997a918 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -9,7 +9,7 @@ var [...a5] = [1, 2, 3]; var [x14, ...a6] = [1, 2, 3]; >x14 : number >a6 : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -18,7 +18,7 @@ var [x15, y15, ...a7] = [1, 2, 3]; >x15 : number >y15 : number >a7 : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -27,8 +27,8 @@ var [x16, y16, z16, ...a8] = [1, 2, 3]; >x16 : number >y16 : number >z16 : number ->a8 : number[] ->[1, 2, 3] : number[] +>a8 : any[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -41,28 +41,28 @@ var [...a9] = [1, "hello", true]; >true : true var [x17, ...a10] = [1, "hello", true]; ->x17 : string | number | boolean ->a10 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x17 : number +>a10 : (string | boolean)[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true var [x18, y18, ...a12] = [1, "hello", true]; ->x18 : string | number | boolean ->y18 : string | number | boolean ->a12 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x18 : number +>y18 : string +>a12 : boolean[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true var [x19, y19, z19, ...a13] = [1, "hello", true]; ->x19 : string | number | boolean ->y19 : string | number | boolean ->z19 : string | number | boolean ->a13 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x19 : number +>y19 : string +>z19 : boolean +>a13 : any[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 64bd8d7e57825..920f995ef3202 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -103,7 +103,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): } function f8() { - var [a, b, c] = []; // Ok, [] is an array + var [a, b, c] = []; // Error, [] is an empty tuple ~ !!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ @@ -224,32 +224,36 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): } function f20() { - var a: number[]; var x: number; var y: number; var z: number; + var a: number[]; + var a3: any[]; var [...a] = [1, 2, 3]; var [x, ...a] = [1, 2, 3]; var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a] = [1, 2, 3]; + var [x, y, z, ...a3] = [1, 2, 3]; [...a] = [1, 2, 3]; [x, ...a] = [1, 2, 3]; [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a] = [1, 2, 3]; + [x, y, z, ...a3] = [1, 2, 3]; } function f21() { - var a: (number | string | boolean)[]; - var x: number | string | boolean; - var y: number | string | boolean; - var z: number | string | boolean; - var [...a] = [1, "hello", true]; - var [x, ...a] = [1, "hello", true]; - var [x, y, ...a] = [1, "hello", true]; - var [x, y, z, ...a] = [1, "hello", true]; - [...a] = [1, "hello", true]; - [x, ...a] = [1, "hello", true]; - [x, y, ...a] = [1, "hello", true]; - [x, y, z, ...a] = [1, "hello", true]; + var x: number; + var y: string; + var z: boolean; + var a0: (number | string | boolean)[]; + var a1: (string | boolean)[]; + var a2: boolean[]; + var a3: any[]; + var [...a0] = [1, "hello", true]; + var [x, ...a1] = [1, "hello", true]; + var [x, y, ...a2] = [1, "hello", true]; + var [x, y, z, ...a3] = [1, "hello", true]; + [...a0] = [1, "hello", true]; + [x, ...a1] = [1, "hello", true]; + [x, y, ...a2] = [1, "hello", true]; + [x, y, z, ...a3] = [1, "hello", true]; } \ No newline at end of file diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index 74d7cd941563e..b4bba2412893a 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -60,7 +60,7 @@ function f7() { } function f8() { - var [a, b, c] = []; // Ok, [] is an array + var [a, b, c] = []; // Error, [] is an empty tuple var [d, e, f] = [1]; // Error, [1] is a tuple } @@ -150,33 +150,37 @@ function f19() { } function f20() { - var a: number[]; var x: number; var y: number; var z: number; + var a: number[]; + var a3: any[]; var [...a] = [1, 2, 3]; var [x, ...a] = [1, 2, 3]; var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a] = [1, 2, 3]; + var [x, y, z, ...a3] = [1, 2, 3]; [...a] = [1, 2, 3]; [x, ...a] = [1, 2, 3]; [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a] = [1, 2, 3]; + [x, y, z, ...a3] = [1, 2, 3]; } function f21() { - var a: (number | string | boolean)[]; - var x: number | string | boolean; - var y: number | string | boolean; - var z: number | string | boolean; - var [...a] = [1, "hello", true]; - var [x, ...a] = [1, "hello", true]; - var [x, y, ...a] = [1, "hello", true]; - var [x, y, z, ...a] = [1, "hello", true]; - [...a] = [1, "hello", true]; - [x, ...a] = [1, "hello", true]; - [x, y, ...a] = [1, "hello", true]; - [x, y, z, ...a] = [1, "hello", true]; + var x: number; + var y: string; + var z: boolean; + var a0: (number | string | boolean)[]; + var a1: (string | boolean)[]; + var a2: boolean[]; + var a3: any[]; + var [...a0] = [1, "hello", true]; + var [x, ...a1] = [1, "hello", true]; + var [x, y, ...a2] = [1, "hello", true]; + var [x, y, z, ...a3] = [1, "hello", true]; + [...a0] = [1, "hello", true]; + [x, ...a1] = [1, "hello", true]; + [x, y, ...a2] = [1, "hello", true]; + [x, y, z, ...a3] = [1, "hello", true]; } @@ -235,7 +239,7 @@ function f7() { var y; } function f8() { - var _a = [], a = _a[0], b = _a[1], c = _a[2]; // Ok, [] is an array + var _a = [], a = _a[0], b = _a[1], c = _a[2]; // Error, [] is an empty tuple var _b = [1], d = _b[0], e = _b[1], f = _b[2]; // Error, [1] is a tuple } function f9() { @@ -318,31 +322,35 @@ function f19() { } function f20() { var _a, _b, _c; - var a; var x; var y; var z; + var a; + var a3; var a = [1, 2, 3].slice(0); var _d = [1, 2, 3], x = _d[0], a = _d.slice(1); var _e = [1, 2, 3], x = _e[0], y = _e[1], a = _e.slice(2); - var _f = [1, 2, 3], x = _f[0], y = _f[1], z = _f[2], a = _f.slice(3); + var _f = [1, 2, 3], x = _f[0], y = _f[1], z = _f[2], a3 = _f.slice(3); a = [1, 2, 3].slice(0); _a = [1, 2, 3], x = _a[0], a = _a.slice(1); _b = [1, 2, 3], x = _b[0], y = _b[1], a = _b.slice(2); - _c = [1, 2, 3], x = _c[0], y = _c[1], z = _c[2], a = _c.slice(3); + _c = [1, 2, 3], x = _c[0], y = _c[1], z = _c[2], a3 = _c.slice(3); } function f21() { var _a, _b, _c; - var a; var x; var y; var z; - var a = [1, "hello", true].slice(0); - var _d = [1, "hello", true], x = _d[0], a = _d.slice(1); - var _e = [1, "hello", true], x = _e[0], y = _e[1], a = _e.slice(2); - var _f = [1, "hello", true], x = _f[0], y = _f[1], z = _f[2], a = _f.slice(3); - a = [1, "hello", true].slice(0); - _a = [1, "hello", true], x = _a[0], a = _a.slice(1); - _b = [1, "hello", true], x = _b[0], y = _b[1], a = _b.slice(2); - _c = [1, "hello", true], x = _c[0], y = _c[1], z = _c[2], a = _c.slice(3); + var a0; + var a1; + var a2; + var a3; + var a0 = [1, "hello", true].slice(0); + var _d = [1, "hello", true], x = _d[0], a1 = _d.slice(1); + var _e = [1, "hello", true], x = _e[0], y = _e[1], a2 = _e.slice(2); + var _f = [1, "hello", true], x = _f[0], y = _f[1], z = _f[2], a3 = _f.slice(3); + a0 = [1, "hello", true].slice(0); + _a = [1, "hello", true], x = _a[0], a1 = _a.slice(1); + _b = [1, "hello", true], x = _b[0], y = _b[1], a2 = _b.slice(2); + _c = [1, "hello", true], x = _c[0], y = _c[1], z = _c[2], a3 = _c.slice(3); } diff --git a/tests/baselines/reference/declarationsAndAssignments.symbols b/tests/baselines/reference/declarationsAndAssignments.symbols index 60518a541f88a..900d255345cb8 100644 --- a/tests/baselines/reference/declarationsAndAssignments.symbols +++ b/tests/baselines/reference/declarationsAndAssignments.symbols @@ -189,7 +189,7 @@ function f7() { function f8() { >f8 : Symbol(f8, Decl(declarationsAndAssignments.ts, 58, 1)) - var [a, b, c] = []; // Ok, [] is an array + var [a, b, c] = []; // Error, [] is an empty tuple >a : Symbol(a, Decl(declarationsAndAssignments.ts, 61, 9)) >b : Symbol(b, Decl(declarationsAndAssignments.ts, 61, 11)) >c : Symbol(c, Decl(declarationsAndAssignments.ts, 61, 14)) @@ -474,104 +474,116 @@ function f19() { function f20() { >f20 : Symbol(f20, Decl(declarationsAndAssignments.ts, 148, 1)) - var a: number[]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) - var x: number; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) var y: number; ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 11)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) var z: number; ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 158, 14)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) + + var a: number[]; +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) + + var a3: any[]; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) var [...a] = [1, 2, 3]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) var [x, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) var [x, y, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - var [x, y, z, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 158, 14)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) + var [x, y, z, ...a3] = [1, 2, 3]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) [...a] = [1, 2, 3]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) [x, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) [x, y, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) - - [x, y, z, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 158, 14)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 155, 9), Decl(declarationsAndAssignments.ts, 156, 11), Decl(declarationsAndAssignments.ts, 157, 14), Decl(declarationsAndAssignments.ts, 158, 17)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) +>a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) + + [x, y, z, ...a3] = [1, 2, 3]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) } function f21() { ->f21 : Symbol(f21, Decl(declarationsAndAssignments.ts, 163, 1)) +>f21 : Symbol(f21, Decl(declarationsAndAssignments.ts, 164, 1)) + + var x: number; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) + + var y: string; +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) + + var z: boolean; +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) - var a: (number | string | boolean)[]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + var a0: (number | string | boolean)[]; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - var x: number | string | boolean; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) + var a1: (string | boolean)[]; +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - var y: number | string | boolean; ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 172, 11), Decl(declarationsAndAssignments.ts, 173, 11)) + var a2: boolean[]; +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - var z: number | string | boolean; ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 173, 14)) + var a3: any[]; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) - var [...a] = [1, "hello", true]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + var [...a0] = [1, "hello", true]; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - var [x, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + var [x, ...a1] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - var [x, y, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 172, 11), Decl(declarationsAndAssignments.ts, 173, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + var [x, y, ...a2] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - var [x, y, z, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 172, 11), Decl(declarationsAndAssignments.ts, 173, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 173, 14)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + var [x, y, z, ...a3] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) - [...a] = [1, "hello", true]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + [...a0] = [1, "hello", true]; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - [x, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + [x, ...a1] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - [x, y, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 172, 11), Decl(declarationsAndAssignments.ts, 173, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + [x, y, ...a2] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - [x, y, z, ...a] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 171, 9), Decl(declarationsAndAssignments.ts, 172, 9), Decl(declarationsAndAssignments.ts, 173, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 172, 11), Decl(declarationsAndAssignments.ts, 173, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 173, 14)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 166, 7), Decl(declarationsAndAssignments.ts, 170, 9), Decl(declarationsAndAssignments.ts, 171, 11), Decl(declarationsAndAssignments.ts, 172, 14), Decl(declarationsAndAssignments.ts, 173, 17)) + [x, y, z, ...a3] = [1, "hello", true]; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) } diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index 10571cf431232..602ffbd76eb0d 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -24,7 +24,7 @@ function f0() { >x : number >y : string >z : any ->[1, "hello"] : [number, string, undefined] +>[1, "hello"] : [number, string, undefined?] >1 : 1 >"hello" : "hello" @@ -254,17 +254,17 @@ function f7() { function f8() { >f8 : () => void - var [a, b, c] = []; // Ok, [] is an array + var [a, b, c] = []; // Error, [] is an empty tuple >a : any >b : any >c : any ->[] : [undefined, undefined, undefined] +>[] : [undefined?, undefined?, undefined?] var [d, e, f] = [1]; // Error, [1] is a tuple >d : number >e : any >f : any ->[1] : [number, undefined, undefined] +>[1] : [number, undefined?, undefined?] >1 : 1 } @@ -681,9 +681,6 @@ function f19() { function f20() { >f20 : () => void - var a: number[]; ->a : number[] - var x: number; >x : number @@ -693,6 +690,12 @@ function f20() { var z: number; >z : number + var a: number[]; +>a : number[] + + var a3: any[]; +>a3 : any[] + var [...a] = [1, 2, 3]; >a : number[] >[1, 2, 3] : number[] @@ -703,7 +706,7 @@ function f20() { var [x, ...a] = [1, 2, 3]; >x : number >a : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -712,17 +715,17 @@ function f20() { >x : number >y : number >a : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 - var [x, y, z, ...a] = [1, 2, 3]; + var [x, y, z, ...a3] = [1, 2, 3]; >x : number >y : number >z : number ->a : number[] ->[1, 2, 3] : number[] +>a3 : any[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -738,37 +741,37 @@ function f20() { >3 : 3 [x, ...a] = [1, 2, 3]; ->[x, ...a] = [1, 2, 3] : number[] ->[x, ...a] : number[] +>[x, ...a] = [1, 2, 3] : [number, number, number] +>[x, ...a] : [number, ...number[]] >x : number >...a : number >a : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 [x, y, ...a] = [1, 2, 3]; ->[x, y, ...a] = [1, 2, 3] : number[] ->[x, y, ...a] : number[] +>[x, y, ...a] = [1, 2, 3] : [number, number, number] +>[x, y, ...a] : [number, number, ...number[]] >x : number >y : number >...a : number >a : number[] ->[1, 2, 3] : number[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 - [x, y, z, ...a] = [1, 2, 3]; ->[x, y, z, ...a] = [1, 2, 3] : number[] ->[x, y, z, ...a] : number[] + [x, y, z, ...a3] = [1, 2, 3]; +>[x, y, z, ...a3] = [1, 2, 3] : [number, number, number] +>[x, y, z, ...a3] : [number, number, number, ...any[]] >x : number >y : number >z : number ->...a : number ->a : number[] ->[1, 2, 3] : number[] +>...a3 : any +>a3 : any[] +>[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 >3 : 3 @@ -777,94 +780,103 @@ function f20() { function f21() { >f21 : () => void - var a: (number | string | boolean)[]; ->a : (string | number | boolean)[] + var x: number; +>x : number - var x: number | string | boolean; ->x : string | number | boolean + var y: string; +>y : string - var y: number | string | boolean; ->y : string | number | boolean + var z: boolean; +>z : boolean - var z: number | string | boolean; ->z : string | number | boolean + var a0: (number | string | boolean)[]; +>a0 : (string | number | boolean)[] - var [...a] = [1, "hello", true]; ->a : (string | number | boolean)[] + var a1: (string | boolean)[]; +>a1 : (string | boolean)[] + + var a2: boolean[]; +>a2 : boolean[] + + var a3: any[]; +>a3 : any[] + + var [...a0] = [1, "hello", true]; +>a0 : (string | number | boolean)[] >[1, "hello", true] : (string | number | boolean)[] >1 : 1 >"hello" : "hello" >true : true - var [x, ...a] = [1, "hello", true]; ->x : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] + var [x, ...a1] = [1, "hello", true]; +>x : number +>a1 : (string | boolean)[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true - var [x, y, ...a] = [1, "hello", true]; ->x : string | number | boolean ->y : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] + var [x, y, ...a2] = [1, "hello", true]; +>x : number +>y : string +>a2 : boolean[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true - var [x, y, z, ...a] = [1, "hello", true]; ->x : string | number | boolean ->y : string | number | boolean ->z : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] + var [x, y, z, ...a3] = [1, "hello", true]; +>x : number +>y : string +>z : boolean +>a3 : any[] +>[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" >true : true - [...a] = [1, "hello", true]; ->[...a] = [1, "hello", true] : (string | number | true)[] ->[...a] : (string | number | boolean)[] ->...a : string | number | boolean ->a : (string | number | boolean)[] + [...a0] = [1, "hello", true]; +>[...a0] = [1, "hello", true] : (string | number | true)[] +>[...a0] : (string | number | boolean)[] +>...a0 : string | number | boolean +>a0 : (string | number | boolean)[] >[1, "hello", true] : (string | number | true)[] >1 : 1 >"hello" : "hello" >true : true - [x, ...a] = [1, "hello", true]; ->[x, ...a] = [1, "hello", true] : (string | number | true)[] ->[x, ...a] : (string | number | boolean)[] ->x : string | number | boolean ->...a : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | true)[] + [x, ...a1] = [1, "hello", true]; +>[x, ...a1] = [1, "hello", true] : [number, string, true] +>[x, ...a1] : [number, ...(string | boolean)[]] +>x : number +>...a1 : string | boolean +>a1 : (string | boolean)[] +>[1, "hello", true] : [number, string, true] >1 : 1 >"hello" : "hello" >true : true - [x, y, ...a] = [1, "hello", true]; ->[x, y, ...a] = [1, "hello", true] : (string | number | true)[] ->[x, y, ...a] : (string | number | boolean)[] ->x : string | number | boolean ->y : string | number | boolean ->...a : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | true)[] + [x, y, ...a2] = [1, "hello", true]; +>[x, y, ...a2] = [1, "hello", true] : [number, string, true] +>[x, y, ...a2] : [number, string, ...boolean[]] +>x : number +>y : string +>...a2 : boolean +>a2 : boolean[] +>[1, "hello", true] : [number, string, true] >1 : 1 >"hello" : "hello" >true : true - [x, y, z, ...a] = [1, "hello", true]; ->[x, y, z, ...a] = [1, "hello", true] : (string | number | true)[] ->[x, y, z, ...a] : (string | number | boolean)[] ->x : string | number | boolean ->y : string | number | boolean ->z : string | number | boolean ->...a : string | number | boolean ->a : (string | number | boolean)[] ->[1, "hello", true] : (string | number | true)[] + [x, y, z, ...a3] = [1, "hello", true]; +>[x, y, z, ...a3] = [1, "hello", true] : [number, string, true] +>[x, y, z, ...a3] : [number, string, boolean, ...any[]] +>x : number +>y : string +>z : boolean +>...a3 : any +>a3 : any[] +>[1, "hello", true] : [number, string, true] >1 : 1 >"hello" : "hello" >true : true diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 3ad1bfa1dd21d..2d212b1e13e7f 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -93,18 +93,18 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [undefined] +>[] : [undefined?] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] +>[[[]], [[[[]]]]] : [[[undefined?]], [[[[undefined?]]]]] +>[[]] : [[undefined?]] +>[] : [undefined?] +>[[[[]]]] : [[[[undefined?]]]] +>[[[]]] : [[[undefined?]]] +>[[]] : [[undefined?]] +>[] : [undefined?] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number @@ -149,7 +149,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined >c10 : (string | number)[] ->[1, 2, 3, 4, "hello"] : (string | number)[] +>[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 >3 : 3 @@ -157,10 +157,10 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : "hello" var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number ->c12 : string | number ->c13 : (string | number)[] ->[1, 2, "string"] : (string | number)[] +>c11 : number +>c12 : number +>c13 : string[] +>[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 >"string" : "string" diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types index 1c46f553d4dfd..8ef92a8875549 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types @@ -93,18 +93,18 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [undefined] +>[] : [undefined?] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] +>[[[]], [[[[]]]]] : [[[undefined?]], [[[[undefined?]]]]] +>[[]] : [[undefined?]] +>[] : [undefined?] +>[[[[]]]] : [[[[undefined?]]]] +>[[[]]] : [[[undefined?]]] +>[[]] : [[undefined?]] +>[] : [undefined?] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number @@ -149,7 +149,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined >c10 : (string | number)[] ->[1, 2, 3, 4, "hello"] : (string | number)[] +>[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 >3 : 3 @@ -157,10 +157,10 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : "hello" var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number ->c12 : string | number ->c13 : (string | number)[] ->[1, 2, "string"] : (string | number)[] +>c11 : number +>c12 : number +>c13 : string[] +>[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 >"string" : "string" diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 3a51965df3161..7767cadee5a78 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -93,18 +93,18 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [undefined] +>[] : [undefined?] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] +>[[[]], [[[[]]]]] : [[[undefined?]], [[[[undefined?]]]]] +>[[]] : [[undefined?]] +>[] : [undefined?] +>[[[[]]]] : [[[[undefined?]]]] +>[[[]]] : [[[undefined?]]] +>[[]] : [[undefined?]] +>[] : [undefined?] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number @@ -149,7 +149,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined >c10 : (string | number)[] ->[1, 2, 3, 4, "hello"] : (string | number)[] +>[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 >3 : 3 @@ -157,10 +157,10 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : "hello" var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number ->c12 : string | number ->c13 : (string | number)[] ->[1, 2, "string"] : (string | number)[] +>c11 : number +>c12 : number +>c13 : string[] +>[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 >"string" : "string" diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types index 1a8eb31fd80b3..97ccf4930e6af 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types @@ -4,7 +4,7 @@ var [[a0], [[a1]]] = [] // Error >a0 : any >a1 : any ->[] : [undefined, undefined] +>[] : [undefined?, undefined?] var [[a2], [[a3]]] = undefined // Error >a2 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types index 542a8ad1b3610..0fb81ba6aa308 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types @@ -3,7 +3,7 @@ const [a, b = a] = [1]; // ok >a : any >b : any >a : any ->[1] : [number, any] +>[1] : [number, any?] >1 : 1 const [c, d = c, e = e] = [1]; // error for e = e @@ -12,7 +12,7 @@ const [c, d = c, e = e] = [1]; // error for e = e >c : any >e : any >e : any ->[1] : [number, any, any] +>[1] : [number, any?, any?] >1 : 1 const [f, g = f, h = i, i = f] = [1]; // error for h = i @@ -23,7 +23,7 @@ const [f, g = f, h = i, i = f] = [1]; // error for h = i >i : any >i : any >f : any ->[1] : [number, any, any, any] +>[1] : [number, any?, any?, any?] >1 : 1 (function ([a, b = a]) { // ok diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index c7a5c44f1d46d..5977fb4bea2ab 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -229,7 +229,7 @@ function c5([a, b, [[c]]]) { } >c : any function c6([a, b, [[c=1]]]) { } ->c6 : ([a, b, [[c]]]: [any, any, [[number]]]) => void +>c6 : ([a, b, [[c]]]: [any, any, [[number?]]]) => void >a : any >b : any >c : number diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index b41a202758660..7601de8ac92bc 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -229,7 +229,7 @@ function c5([a, b, [[c]]]) { } >c : any function c6([a, b, [[c=1]]]) { } ->c6 : ([a, b, [[c]]]: [any, any, [[number]]]) => void +>c6 : ([a, b, [[c]]]: [any, any, [[number?]]]) => void >a : any >b : any >c : number diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index 9de904efdec64..8a6f5d6ca4222 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -212,7 +212,7 @@ function c5([a, b, [[c]]]) { } >c : any function c6([a, b, [[c=1]]]) { } ->c6 : ([a, b, [[c]]]: [any, any, [[number]]]) => void +>c6 : ([a, b, [[c]]]: [any, any, [[number?]]]) => void >a : any >b : any >c : number diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 46a816af349f2..6e4b3f1ad081a 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -28,10 +28,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. Type 'boolean' is not assignable to type '[[any]]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(40,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. - Type '[[string]]' is not assignable to type '[[number]]'. - Type '[string]' is not assignable to type '[number]'. - Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(40,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number?]]]'. + Type '[[string]]' is not assignable to type '[[number?]]'. + Type '[string]' is not assignable to type '[number?]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(47,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. @@ -131,10 +132,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( !!! error TS2345: Type 'boolean' is not assignable to type '[[any]]'. c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. -!!! error TS2345: Type '[[string]]' is not assignable to type '[[number]]'. -!!! error TS2345: Type '[string]' is not assignable to type '[number]'. -!!! error TS2345: Type 'string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number?]]]'. +!!! error TS2345: Type '[[string]]' is not assignable to type '[[number?]]'. +!!! error TS2345: Type '[string]' is not assignable to type '[number?]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. // A parameter can be marked optional by following its name or binding pattern with a question mark (?) // or by including an initializer. Initializers (including binding property or element initializers) are diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.types b/tests/baselines/reference/destructuringParameterDeclaration2.types index 5810f5bca98cd..44f7690ee1f5e 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.types +++ b/tests/baselines/reference/destructuringParameterDeclaration2.types @@ -143,7 +143,7 @@ function c5([a, b, [[c]]]) { } >c : any function c6([a, b, [[c = 1]]]) { } ->c6 : ([a, b, [[c]]]: [any, any, [[number]]]) => void +>c6 : ([a, b, [[c]]]: [any, any, [[number?]]]) => void >a : any >b : any >c : number @@ -193,7 +193,7 @@ c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer >c6([1, 2, [["string"]]]) : void ->c6 : ([a, b, [[c]]]: [any, any, [[number]]]) => void +>c6 : ([a, b, [[c]]]: [any, any, [[number?]]]) => void >[1, 2, [["string"]]] : (number | string[][])[] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt index 3b16993a047a5..d3d7cc97b519b 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt @@ -1,9 +1,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property 'length' are incompatible. Type '5' is not assignable to type '3'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(29,5): error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Types of property '2' are incompatible. + Type 'number' is not assignable to type '[[any]]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Property '2' is missing in type '[number, number]'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts (3 errors) ==== // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -37,7 +42,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5. a10([1, 2, [["string"]], false, true]); // Parameter type is any[] a10([1, 2, 3, false, true]); // Parameter type is any[] + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '[[any]]'. a10([1, 2]); // Parameter type is any[] + ~~~~~~ +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Property '2' is missing in type '[number, number]'. a11([1, 2]); // Parameter type is number[] // Rest parameter with generic diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index 33e0d3b6bd868..e9d2abd14b6d2 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -52,7 +52,7 @@ function a9([a, b, [[c]]]) { } >c : any function a10([a, b, [[c]], ...x]) { } ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >a : any >b : any >c : any @@ -107,19 +107,19 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] >1 : 1 >2 : 2 ->[["string"]] : string[][] ->["string"] : string[] +>[["string"]] : [[string]] +>["string"] : [string] >"string" : "string" >false : false >true : true a10([1, 2, 3, false, true]); // Parameter type is any[] >a10([1, 2, 3, false, true]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2, 3, false, true] : (number | boolean)[] >1 : 1 >2 : 2 @@ -129,7 +129,7 @@ a10([1, 2, 3, false, true]); // Parameter type is any[] a10([1, 2]); // Parameter type is any[] >a10([1, 2]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2] : number[] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt index f0dbf325ed4c0..fa08518279e67 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt @@ -1,9 +1,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property 'length' are incompatible. Type '5' is not assignable to type '3'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(29,5): error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Types of property '2' are incompatible. + Type 'number' is not assignable to type '[[any]]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Property '2' is missing in type '[number, number]'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts (3 errors) ==== // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -37,7 +42,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5i a10([1, 2, [["string"]], false, true]); // Parameter type is any[] a10([1, 2, 3, false, true]); // Parameter type is any[] + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '[[any]]'. a10([1, 2]); // Parameter type is any[] + ~~~~~~ +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Property '2' is missing in type '[number, number]'. a11([1, 2]); // Parameter type is number[] // Rest parameter with generic diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types index 931e149ffe2b4..7f26813108db9 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types @@ -52,7 +52,7 @@ function a9([a, b, [[c]]]) { } >c : any function a10([a, b, [[c]], ...x]) { } ->a10 : ([a, b, [[c]], ...x]: any[]) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >a : any >b : any >c : any @@ -107,19 +107,19 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void ->a10 : ([a, b, [[c]], ...x]: any[]) => void ->[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] >1 : 1 >2 : 2 ->[["string"]] : string[][] ->["string"] : string[] +>[["string"]] : [[string]] +>["string"] : [string] >"string" : "string" >false : false >true : true a10([1, 2, 3, false, true]); // Parameter type is any[] >a10([1, 2, 3, false, true]) : void ->a10 : ([a, b, [[c]], ...x]: any[]) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2, 3, false, true] : (number | boolean)[] >1 : 1 >2 : 2 @@ -129,7 +129,7 @@ a10([1, 2, 3, false, true]); // Parameter type is any[] a10([1, 2]); // Parameter type is any[] >a10([1, 2]) : void ->a10 : ([a, b, [[c]], ...x]: any[]) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2] : number[] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt index 67a5c1bf87fb4..238e155e954cd 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt @@ -1,9 +1,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property 'length' are incompatible. Type '5' is not assignable to type '3'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(29,5): error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Types of property '2' are incompatible. + Type 'number' is not assignable to type '[[any]]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. + Property '2' is missing in type '[number, number]'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts (3 errors) ==== // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -37,7 +42,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6. a10([1, 2, [["string"]], false, true]); // Parameter type is any[] a10([1, 2, 3, false, true]); // Parameter type is any[] + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '[[any]]'. a10([1, 2]); // Parameter type is any[] + ~~~~~~ +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'. +!!! error TS2345: Property '2' is missing in type '[number, number]'. a11([1, 2]); // Parameter type is number[] // Rest parameter with generic diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index dc5e64d2c2cea..6dce00357b547 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -52,7 +52,7 @@ function a9([a, b, [[c]]]) { } >c : any function a10([a, b, [[c]], ...x]) { } ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >a : any >b : any >c : any @@ -107,19 +107,19 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] >1 : 1 >2 : 2 ->[["string"]] : string[][] ->["string"] : string[] +>[["string"]] : [[string]] +>["string"] : [string] >"string" : "string" >false : false >true : true a10([1, 2, 3, false, true]); // Parameter type is any[] >a10([1, 2, 3, false, true]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2, 3, false, true] : (number | boolean)[] >1 : 1 >2 : 2 @@ -129,7 +129,7 @@ a10([1, 2, 3, false, true]); // Parameter type is any[] a10([1, 2]); // Parameter type is any[] >a10([1, 2]) : void ->a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a10 : ([a, b, [[c]], ...x]: [any, any, [[any]], ...any[]]) => void >[1, 2] : number[] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index cdc7938d1af64..6cd6c92ca62d6 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer. @@ -17,7 +16,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (12 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (11 errors) ==== // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -29,8 +28,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( type stringOrNumArray = Array; function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. function a1(...x: (number|string)[]) { } function a2(...a: someArray) { } // Error, rest parameter must be array type ~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.types b/tests/baselines/reference/destructuringParameterDeclaration4.types index feae425d20991..5ad05a4820480 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.types +++ b/tests/baselines/reference/destructuringParameterDeclaration4.types @@ -22,7 +22,7 @@ type stringOrNumArray = Array; >Number : Number function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type ->a0 : (...x: [number, number, string]) => void +>a0 : (x_0: number, x_1: number, x_2: string) => void >x : [number, number, string] function a1(...x: (number|string)[]) { } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index c3fbcb22d5d46..58427ebd849aa 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : true var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean ->d4 : string | number | boolean ->[1, "string", ...temp1] : (string | number | boolean)[] +>d3 : number +>d4 : string +>[1, "string", ...temp1] : [number, string, ...boolean[]] >1 : 1 >"string" : "string" >...temp1 : boolean @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined?]; } +>f : [number, number, { f3: number; f5: number; }, undefined?] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined?] >1 : 1 >2 : 2 >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types index d52e7a51da87f..f8d01563d50b6 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : true var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean ->d4 : string | number | boolean ->[1, "string", ...temp1] : (string | number | boolean)[] +>d3 : number +>d4 : string +>[1, "string", ...temp1] : [number, string, ...boolean[]] >1 : 1 >"string" : "string" >...temp1 : boolean @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined?]; } +>f : [number, number, { f3: number; f5: number; }, undefined?] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined?] >1 : 1 >2 : 2 >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index ce4dfe0679d9f..8b9566c3e1ce7 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : true var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean ->d4 : string | number | boolean ->[1, "string", ...temp1] : (string | number | boolean)[] +>d3 : number +>d4 : string +>[1, "string", ...temp1] : [number, string, ...boolean[]] >1 : 1 >"string" : "string" >...temp1 : boolean @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined?]; } +>f : [number, number, { f3: number; f5: number; }, undefined?] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined?] >1 : 1 >2 : 2 >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt index c831b10a467fb..fe8255ca55652 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt @@ -5,11 +5,9 @@ tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(4 Type '[[boolean]]' is not assignable to type '[[string]]'. Type '[boolean]' is not assignable to type '[string]'. Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,16): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,24): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. -==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts (4 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts (2 errors) ==== // The type T associated with a destructuring variable declaration is determined as follows: // If the declaration includes a type annotation, T is that type. var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error @@ -33,10 +31,6 @@ tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(1 // If the binding element is a rest element, T is an array type with // an element type E, where E is the type of the numeric index signature of S. var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error - ~~ -!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. - ~~ -!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. // When a destructuring variable declaration, binding property, or binding element specifies // an initializer expression, the type of the initializer expression is required to be assignable diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.symbols b/tests/baselines/reference/destructuringVariableDeclaration2.symbols index 8f7c2bfe56a89..8581ab21740e0 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.symbols +++ b/tests/baselines/reference/destructuringVariableDeclaration2.symbols @@ -35,6 +35,7 @@ var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error >c1 : Symbol(c1, Decl(destructuringVariableDeclaration2.ts, 13, 5)) >c2 : Symbol(c2, Decl(destructuringVariableDeclaration2.ts, 13, 8)) +>c3 : Symbol(c3, Decl(destructuringVariableDeclaration2.ts, 13, 48)) >c4 : Symbol(c4, Decl(destructuringVariableDeclaration2.ts, 13, 14)) >c5 : Symbol(c5, Decl(destructuringVariableDeclaration2.ts, 13, 22)) >c6 : Symbol(c6, Decl(destructuringVariableDeclaration2.ts, 13, 30)) diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.types b/tests/baselines/reference/destructuringVariableDeclaration2.types index 666967f91bbf6..8af7ddb7628a4 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.types +++ b/tests/baselines/reference/destructuringVariableDeclaration2.types @@ -53,14 +53,14 @@ var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error // If the binding element is a rest element, T is an array type with // an element type E, where E is the type of the numeric index signature of S. var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error ->c1 : number | { c3: number; c5: number; } ->c2 : number | { c3: number; c5: number; } +>c1 : number +>c2 : number >c3 : any ->c4 : any ->c5 : any +>c4 : number +>c5 : number > : undefined ->c6 : (number | { c3: number; c5: number; })[] ->[1, 2, { c3: 4, c5: 0 }] : (number | { c3: number; c5: number; })[] +>c6 : any[] +>[1, 2, { c3: 4, c5: 0 }] : [number, number, { c3: number; c5: number; }, undefined?] >1 : 1 >2 : 2 >{ c3: 4, c5: 0 } : { c3: number; c5: number; } diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index 51c432f7605b7..f19c1cf2b7ead 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -235,7 +235,7 @@ g1([1, 1]); // (arg: [number, number]) => void function g2([x = 0, y = 0]) { } ->g2 : ([x, y]: [number, number]) => void +>g2 : ([x, y]: [number?, number?]) => void >x : number >0 : 0 >y : number @@ -243,7 +243,7 @@ function g2([x = 0, y = 0]) { } g2([1, 1]); >g2([1, 1]) : void ->g2 : ([x, y]: [number, number]) => void +>g2 : ([x, y]: [number?, number?]) => void >[1, 1] : [number, number] >1 : 1 >1 : 1 @@ -270,40 +270,40 @@ g3([1, 1]); // (arg?: [number, number]) => void function g4([x, y = 0] = [0]) { } ->g4 : ([x, y]?: [number, number]) => void +>g4 : ([x, y]?: [number, number?]) => void >x : number >y : number >0 : 0 ->[0] : [number, number] +>[0] : [number, number?] >0 : 0 g4(); >g4() : void ->g4 : ([x, y]?: [number, number]) => void +>g4 : ([x, y]?: [number, number?]) => void g4([1, 1]); >g4([1, 1]) : void ->g4 : ([x, y]?: [number, number]) => void +>g4 : ([x, y]?: [number, number?]) => void >[1, 1] : [number, number] >1 : 1 >1 : 1 // (arg?: [number, number]) => void function g5([x = 0, y = 0] = []) { } ->g5 : ([x, y]?: [number, number]) => void +>g5 : ([x, y]?: [number?, number?]) => void >x : number >0 : 0 >y : number >0 : 0 ->[] : [number, number] +>[] : [number?, number?] g5(); >g5() : void ->g5 : ([x, y]?: [number, number]) => void +>g5 : ([x, y]?: [number?, number?]) => void g5([1, 1]); >g5([1, 1]) : void ->g5 : ([x, y]?: [number, number]) => void +>g5 : ([x, y]?: [number?, number?]) => void >[1, 1] : [number, number] >1 : 1 >1 : 1 diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types index 725e446e010db..25316e67eb468 100644 --- a/tests/baselines/reference/downlevelLetConst12.types +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -12,7 +12,7 @@ const bar = 1; let [baz] = []; >baz : any ->[] : [undefined] +>[] : [undefined?] let {a: baz2} = { a: 1 }; >a : any @@ -23,7 +23,7 @@ let {a: baz2} = { a: 1 }; const [baz3] = [] >baz3 : any ->[] : [undefined] +>[] : [undefined?] const {a: baz4} = { a: 1 }; >a : any diff --git a/tests/baselines/reference/downlevelLetConst16.types b/tests/baselines/reference/downlevelLetConst16.types index 5655b1f8f15d3..450773fd9bb31 100644 --- a/tests/baselines/reference/downlevelLetConst16.types +++ b/tests/baselines/reference/downlevelLetConst16.types @@ -516,7 +516,7 @@ function foo3() { } for (let [y] = []; ;) { >y : any ->[] : [undefined] +>[] : [undefined?] use(y); >use(y) : any @@ -555,7 +555,7 @@ function foo4() { } for (const [y] = []; ;) { >y : any ->[] : [undefined] +>[] : [undefined?] use(y); >use(y) : any diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.types b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.types index aa715daa30ec0..f21501bf48103 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.types +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.types @@ -40,7 +40,7 @@ function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } >e : any[] function f6([f, ...f]) { } ->f6 : ([f, ...f]: any[]) => void +>f6 : ([f, ...f]: [any, ...any[]]) => void >f : any >f : any[] diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.types b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.types index 1ef1232e1ba50..715d0acc02014 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.types +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.types @@ -43,7 +43,7 @@ function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } >e : any[] function f6([f, ...f]) { } ->f6 : ([f, ...f]: any[]) => void +>f6 : ([f, ...f]: [any, ...any[]]) => void >f : any >f : any[] diff --git a/tests/baselines/reference/emitArrowFunctionES6.types b/tests/baselines/reference/emitArrowFunctionES6.types index 314d5e464b780..db88d3860dae4 100644 --- a/tests/baselines/reference/emitArrowFunctionES6.types +++ b/tests/baselines/reference/emitArrowFunctionES6.types @@ -58,14 +58,14 @@ var p3 = ([, a]) => { }; >a : any var p4 = ([, ...a]) => { }; ->p4 : ([, ...a]: Iterable) => void ->([, ...a]) => { } : ([, ...a]: Iterable) => void +>p4 : ([, ...a]: [any?, ...any[]]) => void +>([, ...a]) => { } : ([, ...a]: [any?, ...any[]]) => void > : undefined >a : any[] var p5 = ([a = 1]) => { }; ->p5 : ([a]: [number]) => void ->([a = 1]) => { } : ([a]: [number]) => void +>p5 : ([a]: [number?]) => void +>([a = 1]) => { } : ([a]: [number?]) => void >a : number >1 : 1 diff --git a/tests/baselines/reference/emptyTuplesTypeAssertion01.errors.txt b/tests/baselines/reference/emptyTuplesTypeAssertion01.errors.txt deleted file mode 100644 index bfe850a5749bf..0000000000000 --- a/tests/baselines/reference/emptyTuplesTypeAssertion01.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion01.ts(1,10): error TS1122: A tuple type element list cannot be empty. - - -==== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion01.ts (1 errors) ==== - let x = <[]>[]; - ~~ -!!! error TS1122: A tuple type element list cannot be empty. - let y = x[0]; \ No newline at end of file diff --git a/tests/baselines/reference/emptyTuplesTypeAssertion01.types b/tests/baselines/reference/emptyTuplesTypeAssertion01.types index 3ccfab4cb616a..0a278c01d3169 100644 --- a/tests/baselines/reference/emptyTuplesTypeAssertion01.types +++ b/tests/baselines/reference/emptyTuplesTypeAssertion01.types @@ -2,7 +2,7 @@ let x = <[]>[]; >x : [] ><[]>[] : [] ->[] : undefined[] +>[] : [] let y = x[0]; >y : never diff --git a/tests/baselines/reference/emptyTuplesTypeAssertion02.errors.txt b/tests/baselines/reference/emptyTuplesTypeAssertion02.errors.txt deleted file mode 100644 index 1bbf96e6aec70..0000000000000 --- a/tests/baselines/reference/emptyTuplesTypeAssertion02.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion02.ts(1,15): error TS1122: A tuple type element list cannot be empty. - - -==== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion02.ts (1 errors) ==== - let x = [] as []; - ~~ -!!! error TS1122: A tuple type element list cannot be empty. - let y = x[0]; \ No newline at end of file diff --git a/tests/baselines/reference/emptyTuplesTypeAssertion02.types b/tests/baselines/reference/emptyTuplesTypeAssertion02.types index 9b791a5e4155d..ef35e90eac2cb 100644 --- a/tests/baselines/reference/emptyTuplesTypeAssertion02.types +++ b/tests/baselines/reference/emptyTuplesTypeAssertion02.types @@ -2,7 +2,7 @@ let x = [] as []; >x : [] >[] as [] : [] ->[] : undefined[] +>[] : [] let y = x[0]; >y : never diff --git a/tests/baselines/reference/for-of49.errors.txt b/tests/baselines/reference/for-of49.errors.txt deleted file mode 100644 index aaf29f5bfe3eb..0000000000000 --- a/tests/baselines/reference/for-of49.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/es6/for-ofStatements/for-of49.ts(3,14): error TS2322: Type 'string | boolean' is not assignable to type 'boolean'. - Type 'string' is not assignable to type 'boolean'. - - -==== tests/cases/conformance/es6/for-ofStatements/for-of49.ts (1 errors) ==== - var k: string, v: boolean; - var map = new Map([["", true]]); - for ([k, ...[v]] of map) { - ~ -!!! error TS2322: Type 'string | boolean' is not assignable to type 'boolean'. -!!! error TS2322: Type 'string' is not assignable to type 'boolean'. - k; - v; - } \ No newline at end of file diff --git a/tests/baselines/reference/for-of49.types b/tests/baselines/reference/for-of49.types index bed54d205ea36..fe46157c2864e 100644 --- a/tests/baselines/reference/for-of49.types +++ b/tests/baselines/reference/for-of49.types @@ -13,7 +13,7 @@ var map = new Map([["", true]]); >true : true for ([k, ...[v]] of map) { ->[k, ...[v]] : (string | boolean)[] +>[k, ...[v]] : [string, ...boolean[]] >k : string >...[v] : boolean >[v] : [boolean] diff --git a/tests/baselines/reference/genericRestParameters1.errors.txt b/tests/baselines/reference/genericRestParameters1.errors.txt new file mode 100644 index 0000000000000..c923426071478 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters1.errors.txt @@ -0,0 +1,164 @@ +tests/cases/conformance/types/rest/genericRestParameters1.ts(22,1): error TS2556: Expected 3 arguments, but got 1 or more. +tests/cases/conformance/types/rest/genericRestParameters1.ts(31,1): error TS2556: Expected 3 arguments, but got 1 or more. + + +==== tests/cases/conformance/types/rest/genericRestParameters1.ts (2 errors) ==== + declare let f1: (...x: [number, string, boolean]) => void; + declare let f2: (x0: number, x1: string, x2: boolean) => void; + + f1 = f2; + f2 = f1; + + declare const t3: [number, string, boolean]; + declare const t2: [string, boolean]; + declare const t1: [boolean]; + declare const t0: []; + + declare const ns: [number, string]; + declare const sn: [string, number]; + + f1(42, "hello", true); + f1(t3[0], t3[1], t3[2]); + f1(...t3); + f1(42, ...t2); + f1(42, "hello", ...t1); + f1(42, "hello", true, ...t0); + f1(ns[0], ns[1], true); + f1(...ns, true); // Error, tuple spread only expanded when last + ~~~~~~~~~~~~~~~ +!!! error TS2556: Expected 3 arguments, but got 1 or more. + + f2(42, "hello", true); + f2(t3[0], t3[1], t3[2]); + f2(...t3); + f2(42, ...t2); + f2(42, "hello", ...t1); + f2(42, "hello", true, ...t0); + f2(ns[0], ns[1], true); + f2(...ns, true); // Error, tuple spread only expanded when last + ~~~~~~~~~~~~~~~ +!!! error TS2556: Expected 3 arguments, but got 1 or more. + + declare function f10(...args: T): T; + + const x10 = f10(42, "hello", true); // [number, string, boolean] + const x11 = f10(42, "hello"); // [number, string] + const x12 = f10(42); // [number] + const x13 = f10(); // [] + const x14 = f10(...t3); // [number, string, boolean] + const x15 = f10(42, ...t2); // [number, string, boolean] + const x16 = f10(42, "hello", ...t1); // [number, string, boolean] + const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] + const x18 = f10(...ns, true); // (string | number | boolean)[] + + function g10(u: U, v: V) { + let x1 = f10(...u); // U + let x2 = f10(...v); // V + let x3 = f10(1, ...u); // [number, ...string[]] + let x4 = f10(...u, ...v); // (string | number)[] + } + + declare function f11(...args: T): T; + + const z10 = f11(42, "hello", true); // [42, "hello", true] + const z11 = f11(42, "hello"); // [42, "hello"] + const z12 = f11(42); // [42] + const z13 = f11(); // [] + const z14 = f11(...t3); // [number, string, boolean] + const z15 = f11(42, ...t2); // [42, string, boolean] + const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] + const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] + const z18 = f11(...ns, true); // (string | number | true)[] + + function g11(u: U, v: V) { + let x1 = f11(...u); // U + let x2 = f11(...v); // V + let x3 = f11(1, ...u); // [1, ...string[]] + let x4 = f11(...u, ...v); // (string | number)[] + } + + function call(f: (...args: T) => U, ...args: T) { + return f(...args); + } + + function callr(args: T, f: (...args: T) => U) { + return f(...args); + } + + declare function f15(a: string, b: number): string | number; + declare function f16(a: A, b: B): A | B; + + let x20 = call((x, y) => x + y, 10, 20); // number + let x21 = call((x, y) => x + y, 10, "hello"); // string + let x22 = call(f15, "hello", 42); // string | number + let x23 = call(f16, "hello", 42); // unknown + let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number + + let x30 = callr(sn, (x, y) => x + y); // string + let x31 = callr(sn, f15); // string | number + let x32 = callr(sn, f16); // string | number + + function bind(f: (x: T, ...rest: U) => V, x: T) { + return (...rest: U) => f(x, ...rest); + } + + declare const f20: (x: number, y: string, z: boolean) => string[]; + + const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] + const f22 = bind(f21, "hello"); // (z: boolean) => string[] + const f23 = bind(f22, true); // () => string[] + + f20(42, "hello", true); + f21("hello", true); + f22(true); + f23(); + + declare const g20: (x: number, y?: string, z?: boolean) => string[]; + + const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] + const g22 = bind(g21, "hello"); // (z: boolean) => string[] + const g23 = bind(g22, true); // () => string[] + + g20(42, "hello", true); + g20(42, "hello"); + g20(42); + g21("hello", true); + g21("hello"); + g21(); + g22(true); + g22(); + g23(); + + declare function f30 any)[]>(x: T, ...args: U): U; + + const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] + + type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; + + type T01 = Parameters<(x: number, y: string, z: boolean) => void>; + type T02 = Parameters<(...args: [number, string, boolean]) => void>; + type T03 = Parameters void>; + type T04 = Parameters void>; + type T05 = Parameters<(...args: T[]) => void>; + type T06 = Parameters void>; + type T07 = Parameters<(...args: T) => void>; + type T08 = Parameters void>; + type T09 = Parameters; + + type Record1 = { + move: [number, 'left' | 'right']; + jump: [number, 'up' | 'down']; + stop: string; + done: []; + } + + type EventType = { + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; + } + + declare var events: EventType; + events.emit('move', 10, 'left'); + events.emit('jump', 20, 'up'); + events.emit('stop', 'Bye!'); + events.emit('done'); + \ No newline at end of file diff --git a/tests/baselines/reference/genericRestParameters1.js b/tests/baselines/reference/genericRestParameters1.js new file mode 100644 index 0000000000000..89d92facba646 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters1.js @@ -0,0 +1,334 @@ +//// [genericRestParameters1.ts] +declare let f1: (...x: [number, string, boolean]) => void; +declare let f2: (x0: number, x1: string, x2: boolean) => void; + +f1 = f2; +f2 = f1; + +declare const t3: [number, string, boolean]; +declare const t2: [string, boolean]; +declare const t1: [boolean]; +declare const t0: []; + +declare const ns: [number, string]; +declare const sn: [string, number]; + +f1(42, "hello", true); +f1(t3[0], t3[1], t3[2]); +f1(...t3); +f1(42, ...t2); +f1(42, "hello", ...t1); +f1(42, "hello", true, ...t0); +f1(ns[0], ns[1], true); +f1(...ns, true); // Error, tuple spread only expanded when last + +f2(42, "hello", true); +f2(t3[0], t3[1], t3[2]); +f2(...t3); +f2(42, ...t2); +f2(42, "hello", ...t1); +f2(42, "hello", true, ...t0); +f2(ns[0], ns[1], true); +f2(...ns, true); // Error, tuple spread only expanded when last + +declare function f10(...args: T): T; + +const x10 = f10(42, "hello", true); // [number, string, boolean] +const x11 = f10(42, "hello"); // [number, string] +const x12 = f10(42); // [number] +const x13 = f10(); // [] +const x14 = f10(...t3); // [number, string, boolean] +const x15 = f10(42, ...t2); // [number, string, boolean] +const x16 = f10(42, "hello", ...t1); // [number, string, boolean] +const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] +const x18 = f10(...ns, true); // (string | number | boolean)[] + +function g10(u: U, v: V) { + let x1 = f10(...u); // U + let x2 = f10(...v); // V + let x3 = f10(1, ...u); // [number, ...string[]] + let x4 = f10(...u, ...v); // (string | number)[] +} + +declare function f11(...args: T): T; + +const z10 = f11(42, "hello", true); // [42, "hello", true] +const z11 = f11(42, "hello"); // [42, "hello"] +const z12 = f11(42); // [42] +const z13 = f11(); // [] +const z14 = f11(...t3); // [number, string, boolean] +const z15 = f11(42, ...t2); // [42, string, boolean] +const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] +const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] +const z18 = f11(...ns, true); // (string | number | true)[] + +function g11(u: U, v: V) { + let x1 = f11(...u); // U + let x2 = f11(...v); // V + let x3 = f11(1, ...u); // [1, ...string[]] + let x4 = f11(...u, ...v); // (string | number)[] +} + +function call(f: (...args: T) => U, ...args: T) { + return f(...args); +} + +function callr(args: T, f: (...args: T) => U) { + return f(...args); +} + +declare function f15(a: string, b: number): string | number; +declare function f16(a: A, b: B): A | B; + +let x20 = call((x, y) => x + y, 10, 20); // number +let x21 = call((x, y) => x + y, 10, "hello"); // string +let x22 = call(f15, "hello", 42); // string | number +let x23 = call(f16, "hello", 42); // unknown +let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number + +let x30 = callr(sn, (x, y) => x + y); // string +let x31 = callr(sn, f15); // string | number +let x32 = callr(sn, f16); // string | number + +function bind(f: (x: T, ...rest: U) => V, x: T) { + return (...rest: U) => f(x, ...rest); +} + +declare const f20: (x: number, y: string, z: boolean) => string[]; + +const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] +const f22 = bind(f21, "hello"); // (z: boolean) => string[] +const f23 = bind(f22, true); // () => string[] + +f20(42, "hello", true); +f21("hello", true); +f22(true); +f23(); + +declare const g20: (x: number, y?: string, z?: boolean) => string[]; + +const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] +const g22 = bind(g21, "hello"); // (z: boolean) => string[] +const g23 = bind(g22, true); // () => string[] + +g20(42, "hello", true); +g20(42, "hello"); +g20(42); +g21("hello", true); +g21("hello"); +g21(); +g22(true); +g22(); +g23(); + +declare function f30 any)[]>(x: T, ...args: U): U; + +const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; + +type T01 = Parameters<(x: number, y: string, z: boolean) => void>; +type T02 = Parameters<(...args: [number, string, boolean]) => void>; +type T03 = Parameters void>; +type T04 = Parameters void>; +type T05 = Parameters<(...args: T[]) => void>; +type T06 = Parameters void>; +type T07 = Parameters<(...args: T) => void>; +type T08 = Parameters void>; +type T09 = Parameters; + +type Record1 = { + move: [number, 'left' | 'right']; + jump: [number, 'up' | 'down']; + stop: string; + done: []; +} + +type EventType = { + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; +} + +declare var events: EventType; +events.emit('move', 10, 'left'); +events.emit('jump', 20, 'up'); +events.emit('stop', 'Bye!'); +events.emit('done'); + + +//// [genericRestParameters1.js] +"use strict"; +f1 = f2; +f2 = f1; +f1(42, "hello", true); +f1(t3[0], t3[1], t3[2]); +f1.apply(void 0, t3); +f1.apply(void 0, [42].concat(t2)); +f1.apply(void 0, [42, "hello"].concat(t1)); +f1.apply(void 0, [42, "hello", true].concat(t0)); +f1(ns[0], ns[1], true); +f1.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last +f2(42, "hello", true); +f2(t3[0], t3[1], t3[2]); +f2.apply(void 0, t3); +f2.apply(void 0, [42].concat(t2)); +f2.apply(void 0, [42, "hello"].concat(t1)); +f2.apply(void 0, [42, "hello", true].concat(t0)); +f2(ns[0], ns[1], true); +f2.apply(void 0, ns.concat([true])); // Error, tuple spread only expanded when last +var x10 = f10(42, "hello", true); // [number, string, boolean] +var x11 = f10(42, "hello"); // [number, string] +var x12 = f10(42); // [number] +var x13 = f10(); // [] +var x14 = f10.apply(void 0, t3); // [number, string, boolean] +var x15 = f10.apply(void 0, [42].concat(t2)); // [number, string, boolean] +var x16 = f10.apply(void 0, [42, "hello"].concat(t1)); // [number, string, boolean] +var x17 = f10.apply(void 0, [42, "hello", true].concat(t0)); // [number, string, boolean] +var x18 = f10.apply(void 0, ns.concat([true])); // (string | number | boolean)[] +function g10(u, v) { + var x1 = f10.apply(void 0, u); // U + var x2 = f10.apply(void 0, v); // V + var x3 = f10.apply(void 0, [1].concat(u)); // [number, ...string[]] + var x4 = f10.apply(void 0, u.concat(v)); // (string | number)[] +} +var z10 = f11(42, "hello", true); // [42, "hello", true] +var z11 = f11(42, "hello"); // [42, "hello"] +var z12 = f11(42); // [42] +var z13 = f11(); // [] +var z14 = f11.apply(void 0, t3); // [number, string, boolean] +var z15 = f11.apply(void 0, [42].concat(t2)); // [42, string, boolean] +var z16 = f11.apply(void 0, [42, "hello"].concat(t1)); // [42, "hello", boolean] +var z17 = f11.apply(void 0, [42, "hello", true].concat(t0)); // [42, "hello", true] +var z18 = f11.apply(void 0, ns.concat([true])); // (string | number | true)[] +function g11(u, v) { + var x1 = f11.apply(void 0, u); // U + var x2 = f11.apply(void 0, v); // V + var x3 = f11.apply(void 0, [1].concat(u)); // [1, ...string[]] + var x4 = f11.apply(void 0, u.concat(v)); // (string | number)[] +} +function call(f) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + return f.apply(void 0, args); +} +function callr(args, f) { + return f.apply(void 0, args); +} +var x20 = call(function (x, y) { return x + y; }, 10, 20); // number +var x21 = call(function (x, y) { return x + y; }, 10, "hello"); // string +var x22 = call(f15, "hello", 42); // string | number +var x23 = call(f16, "hello", 42); // unknown +var x24 = call(f16, "hello", 42); // string | number +var x30 = callr(sn, function (x, y) { return x + y; }); // string +var x31 = callr(sn, f15); // string | number +var x32 = callr(sn, f16); // string | number +function bind(f, x) { + return function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i] = arguments[_i]; + } + return f.apply(void 0, [x].concat(rest)); + }; +} +var f21 = bind(f20, 42); // (y: string, z: boolean) => string[] +var f22 = bind(f21, "hello"); // (z: boolean) => string[] +var f23 = bind(f22, true); // () => string[] +f20(42, "hello", true); +f21("hello", true); +f22(true); +f23(); +var g21 = bind(g20, 42); // (y: string, z: boolean) => string[] +var g22 = bind(g21, "hello"); // (z: boolean) => string[] +var g23 = bind(g22, true); // () => string[] +g20(42, "hello", true); +g20(42, "hello"); +g20(42); +g21("hello", true); +g21("hello"); +g21(); +g22(true); +g22(); +g23(); +var c30 = f30(42, function (x) { return "" + x; }, function (x) { return x + 1; }); // [(x: number) => string, (x: number) => number] +events.emit('move', 10, 'left'); +events.emit('jump', 20, 'up'); +events.emit('stop', 'Bye!'); +events.emit('done'); + + +//// [genericRestParameters1.d.ts] +declare let f1: (...x: [number, string, boolean]) => void; +declare let f2: (x0: number, x1: string, x2: boolean) => void; +declare const t3: [number, string, boolean]; +declare const t2: [string, boolean]; +declare const t1: [boolean]; +declare const t0: []; +declare const ns: [number, string]; +declare const sn: [string, number]; +declare function f10(...args: T): T; +declare const x10: [number, string, boolean]; +declare const x11: [number, string]; +declare const x12: [number]; +declare const x13: []; +declare const x14: [number, string, boolean]; +declare const x15: [number, string, boolean]; +declare const x16: [number, string, boolean]; +declare const x17: [number, string, boolean]; +declare const x18: (string | number | boolean)[]; +declare function g10(u: U, v: V): void; +declare function f11(...args: T): T; +declare const z10: [42, "hello", true]; +declare const z11: [42, "hello"]; +declare const z12: [42]; +declare const z13: []; +declare const z14: [number, string, boolean]; +declare const z15: [42, string, boolean]; +declare const z16: [42, "hello", boolean]; +declare const z17: [42, "hello", true]; +declare const z18: (string | number | true)[]; +declare function g11(u: U, v: V): void; +declare function call(f: (...args: T) => U, ...args: T): U; +declare function callr(args: T, f: (...args: T) => U): U; +declare function f15(a: string, b: number): string | number; +declare function f16(a: A, b: B): A | B; +declare let x20: number; +declare let x21: string; +declare let x22: string | number; +declare let x23: unknown; +declare let x24: string | number; +declare let x30: string; +declare let x31: string | number; +declare let x32: string | number; +declare function bind(f: (x: T, ...rest: U) => V, x: T): (...rest: U) => V; +declare const f20: (x: number, y: string, z: boolean) => string[]; +declare const f21: (y: string, z: boolean) => string[]; +declare const f22: (z: boolean) => string[]; +declare const f23: () => string[]; +declare const g20: (x: number, y?: string, z?: boolean) => string[]; +declare const g21: (y?: string | undefined, z?: boolean | undefined) => string[]; +declare const g22: (z?: boolean | undefined) => string[]; +declare const g23: () => string[]; +declare function f30 any)[]>(x: T, ...args: U): U; +declare const c30: [(x: number) => string, (x: number) => number]; +declare type Parameters = T extends ((...args: infer U) => any) | (new (...args: infer U) => any) ? U : any[]; +declare type T01 = Parameters<(x: number, y: string, z: boolean) => void>; +declare type T02 = Parameters<(...args: [number, string, boolean]) => void>; +declare type T03 = Parameters void>; +declare type T04 = Parameters void>; +declare type T05 = Parameters<(...args: T[]) => void>; +declare type T06 = Parameters void>; +declare type T07 = Parameters<(...args: T) => void>; +declare type T08 = Parameters void>; +declare type T09 = Parameters; +declare type Record1 = { + move: [number, 'left' | 'right']; + jump: [number, 'up' | 'down']; + stop: string; + done: []; +}; +declare type EventType = { + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; +}; +declare var events: EventType; diff --git a/tests/baselines/reference/genericRestParameters1.symbols b/tests/baselines/reference/genericRestParameters1.symbols new file mode 100644 index 0000000000000..d56774eacaea2 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters1.symbols @@ -0,0 +1,624 @@ +=== tests/cases/conformance/types/rest/genericRestParameters1.ts === +declare let f1: (...x: [number, string, boolean]) => void; +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 0, 17)) + +declare let f2: (x0: number, x1: string, x2: boolean) => void; +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>x0 : Symbol(x0, Decl(genericRestParameters1.ts, 1, 17)) +>x1 : Symbol(x1, Decl(genericRestParameters1.ts, 1, 28)) +>x2 : Symbol(x2, Decl(genericRestParameters1.ts, 1, 40)) + +f1 = f2; +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) + +f2 = f1; +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) + +declare const t3: [number, string, boolean]; +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) + +declare const t2: [string, boolean]; +>t2 : Symbol(t2, Decl(genericRestParameters1.ts, 7, 13)) + +declare const t1: [boolean]; +>t1 : Symbol(t1, Decl(genericRestParameters1.ts, 8, 13)) + +declare const t0: []; +>t0 : Symbol(t0, Decl(genericRestParameters1.ts, 9, 13)) + +declare const ns: [number, string]; +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) + +declare const sn: [string, number]; +>sn : Symbol(sn, Decl(genericRestParameters1.ts, 12, 13)) + +f1(42, "hello", true); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) + +f1(t3[0], t3[1], t3[2]); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>0 : Symbol(0) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>1 : Symbol(1) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>2 : Symbol(2) + +f1(...t3); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) + +f1(42, ...t2); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters1.ts, 7, 13)) + +f1(42, "hello", ...t1); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters1.ts, 8, 13)) + +f1(42, "hello", true, ...t0); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>t0 : Symbol(t0, Decl(genericRestParameters1.ts, 9, 13)) + +f1(ns[0], ns[1], true); +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) +>0 : Symbol(0) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) +>1 : Symbol(1) + +f1(...ns, true); // Error, tuple spread only expanded when last +>f1 : Symbol(f1, Decl(genericRestParameters1.ts, 0, 11)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) + +f2(42, "hello", true); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) + +f2(t3[0], t3[1], t3[2]); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>0 : Symbol(0) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>1 : Symbol(1) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) +>2 : Symbol(2) + +f2(...t3); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) + +f2(42, ...t2); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters1.ts, 7, 13)) + +f2(42, "hello", ...t1); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters1.ts, 8, 13)) + +f2(42, "hello", true, ...t0); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>t0 : Symbol(t0, Decl(genericRestParameters1.ts, 9, 13)) + +f2(ns[0], ns[1], true); +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) +>0 : Symbol(0) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) +>1 : Symbol(1) + +f2(...ns, true); // Error, tuple spread only expanded when last +>f2 : Symbol(f2, Decl(genericRestParameters1.ts, 1, 11)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) + +declare function f10(...args: T): T; +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 32, 21)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 32, 42)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 32, 21)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 32, 21)) + +const x10 = f10(42, "hello", true); // [number, string, boolean] +>x10 : Symbol(x10, Decl(genericRestParameters1.ts, 34, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) + +const x11 = f10(42, "hello"); // [number, string] +>x11 : Symbol(x11, Decl(genericRestParameters1.ts, 35, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) + +const x12 = f10(42); // [number] +>x12 : Symbol(x12, Decl(genericRestParameters1.ts, 36, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) + +const x13 = f10(); // [] +>x13 : Symbol(x13, Decl(genericRestParameters1.ts, 37, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) + +const x14 = f10(...t3); // [number, string, boolean] +>x14 : Symbol(x14, Decl(genericRestParameters1.ts, 38, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) + +const x15 = f10(42, ...t2); // [number, string, boolean] +>x15 : Symbol(x15, Decl(genericRestParameters1.ts, 39, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>t2 : Symbol(t2, Decl(genericRestParameters1.ts, 7, 13)) + +const x16 = f10(42, "hello", ...t1); // [number, string, boolean] +>x16 : Symbol(x16, Decl(genericRestParameters1.ts, 40, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>t1 : Symbol(t1, Decl(genericRestParameters1.ts, 8, 13)) + +const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] +>x17 : Symbol(x17, Decl(genericRestParameters1.ts, 41, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>t0 : Symbol(t0, Decl(genericRestParameters1.ts, 9, 13)) + +const x18 = f10(...ns, true); // (string | number | boolean)[] +>x18 : Symbol(x18, Decl(genericRestParameters1.ts, 42, 5)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) + +function g10(u: U, v: V) { +>g10 : Symbol(g10, Decl(genericRestParameters1.ts, 42, 29)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 44, 13)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 44, 32)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 44, 61)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 44, 13)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 44, 66)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 44, 32)) + + let x1 = f10(...u); // U +>x1 : Symbol(x1, Decl(genericRestParameters1.ts, 45, 7)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 44, 61)) + + let x2 = f10(...v); // V +>x2 : Symbol(x2, Decl(genericRestParameters1.ts, 46, 7)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 44, 66)) + + let x3 = f10(1, ...u); // [number, ...string[]] +>x3 : Symbol(x3, Decl(genericRestParameters1.ts, 47, 7)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 44, 61)) + + let x4 = f10(...u, ...v); // (string | number)[] +>x4 : Symbol(x4, Decl(genericRestParameters1.ts, 48, 7)) +>f10 : Symbol(f10, Decl(genericRestParameters1.ts, 30, 16)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 44, 61)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 44, 66)) +} + +declare function f11(...args: T): T; +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 51, 21)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 51, 62)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 51, 21)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 51, 21)) + +const z10 = f11(42, "hello", true); // [42, "hello", true] +>z10 : Symbol(z10, Decl(genericRestParameters1.ts, 53, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) + +const z11 = f11(42, "hello"); // [42, "hello"] +>z11 : Symbol(z11, Decl(genericRestParameters1.ts, 54, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) + +const z12 = f11(42); // [42] +>z12 : Symbol(z12, Decl(genericRestParameters1.ts, 55, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) + +const z13 = f11(); // [] +>z13 : Symbol(z13, Decl(genericRestParameters1.ts, 56, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) + +const z14 = f11(...t3); // [number, string, boolean] +>z14 : Symbol(z14, Decl(genericRestParameters1.ts, 57, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>t3 : Symbol(t3, Decl(genericRestParameters1.ts, 6, 13)) + +const z15 = f11(42, ...t2); // [42, string, boolean] +>z15 : Symbol(z15, Decl(genericRestParameters1.ts, 58, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>t2 : Symbol(t2, Decl(genericRestParameters1.ts, 7, 13)) + +const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] +>z16 : Symbol(z16, Decl(genericRestParameters1.ts, 59, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>t1 : Symbol(t1, Decl(genericRestParameters1.ts, 8, 13)) + +const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] +>z17 : Symbol(z17, Decl(genericRestParameters1.ts, 60, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>t0 : Symbol(t0, Decl(genericRestParameters1.ts, 9, 13)) + +const z18 = f11(...ns, true); // (string | number | true)[] +>z18 : Symbol(z18, Decl(genericRestParameters1.ts, 61, 5)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>ns : Symbol(ns, Decl(genericRestParameters1.ts, 11, 13)) + +function g11(u: U, v: V) { +>g11 : Symbol(g11, Decl(genericRestParameters1.ts, 61, 29)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 63, 13)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 63, 32)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 63, 61)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 63, 13)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 63, 66)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 63, 32)) + + let x1 = f11(...u); // U +>x1 : Symbol(x1, Decl(genericRestParameters1.ts, 64, 7)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 63, 61)) + + let x2 = f11(...v); // V +>x2 : Symbol(x2, Decl(genericRestParameters1.ts, 65, 7)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 63, 66)) + + let x3 = f11(1, ...u); // [1, ...string[]] +>x3 : Symbol(x3, Decl(genericRestParameters1.ts, 66, 7)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 63, 61)) + + let x4 = f11(...u, ...v); // (string | number)[] +>x4 : Symbol(x4, Decl(genericRestParameters1.ts, 67, 7)) +>f11 : Symbol(f11, Decl(genericRestParameters1.ts, 49, 1)) +>u : Symbol(u, Decl(genericRestParameters1.ts, 63, 61)) +>v : Symbol(v, Decl(genericRestParameters1.ts, 63, 66)) +} + +function call(f: (...args: T) => U, ...args: T) { +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 70, 14)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 70, 34)) +>f : Symbol(f, Decl(genericRestParameters1.ts, 70, 38)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 70, 42)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 70, 14)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 70, 34)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 70, 59)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 70, 14)) + + return f(...args); +>f : Symbol(f, Decl(genericRestParameters1.ts, 70, 38)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 70, 59)) +} + +function callr(args: T, f: (...args: T) => U) { +>callr : Symbol(callr, Decl(genericRestParameters1.ts, 72, 1)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 74, 15)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 74, 35)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 74, 39)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 74, 15)) +>f : Symbol(f, Decl(genericRestParameters1.ts, 74, 47)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 74, 52)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 74, 15)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 74, 35)) + + return f(...args); +>f : Symbol(f, Decl(genericRestParameters1.ts, 74, 47)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 74, 39)) +} + +declare function f15(a: string, b: number): string | number; +>f15 : Symbol(f15, Decl(genericRestParameters1.ts, 76, 1)) +>a : Symbol(a, Decl(genericRestParameters1.ts, 78, 21)) +>b : Symbol(b, Decl(genericRestParameters1.ts, 78, 31)) + +declare function f16(a: A, b: B): A | B; +>f16 : Symbol(f16, Decl(genericRestParameters1.ts, 78, 60)) +>A : Symbol(A, Decl(genericRestParameters1.ts, 79, 21)) +>B : Symbol(B, Decl(genericRestParameters1.ts, 79, 23)) +>a : Symbol(a, Decl(genericRestParameters1.ts, 79, 27)) +>A : Symbol(A, Decl(genericRestParameters1.ts, 79, 21)) +>b : Symbol(b, Decl(genericRestParameters1.ts, 79, 32)) +>B : Symbol(B, Decl(genericRestParameters1.ts, 79, 23)) +>A : Symbol(A, Decl(genericRestParameters1.ts, 79, 21)) +>B : Symbol(B, Decl(genericRestParameters1.ts, 79, 23)) + +let x20 = call((x, y) => x + y, 10, 20); // number +>x20 : Symbol(x20, Decl(genericRestParameters1.ts, 81, 3)) +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 81, 16)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 81, 18)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 81, 16)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 81, 18)) + +let x21 = call((x, y) => x + y, 10, "hello"); // string +>x21 : Symbol(x21, Decl(genericRestParameters1.ts, 82, 3)) +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 82, 16)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 82, 18)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 82, 16)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 82, 18)) + +let x22 = call(f15, "hello", 42); // string | number +>x22 : Symbol(x22, Decl(genericRestParameters1.ts, 83, 3)) +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>f15 : Symbol(f15, Decl(genericRestParameters1.ts, 76, 1)) + +let x23 = call(f16, "hello", 42); // unknown +>x23 : Symbol(x23, Decl(genericRestParameters1.ts, 84, 3)) +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>f16 : Symbol(f16, Decl(genericRestParameters1.ts, 78, 60)) + +let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number +>x24 : Symbol(x24, Decl(genericRestParameters1.ts, 85, 3)) +>call : Symbol(call, Decl(genericRestParameters1.ts, 68, 1)) +>f16 : Symbol(f16, Decl(genericRestParameters1.ts, 78, 60)) + +let x30 = callr(sn, (x, y) => x + y); // string +>x30 : Symbol(x30, Decl(genericRestParameters1.ts, 87, 3)) +>callr : Symbol(callr, Decl(genericRestParameters1.ts, 72, 1)) +>sn : Symbol(sn, Decl(genericRestParameters1.ts, 12, 13)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 87, 21)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 87, 23)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 87, 21)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 87, 23)) + +let x31 = callr(sn, f15); // string | number +>x31 : Symbol(x31, Decl(genericRestParameters1.ts, 88, 3)) +>callr : Symbol(callr, Decl(genericRestParameters1.ts, 72, 1)) +>sn : Symbol(sn, Decl(genericRestParameters1.ts, 12, 13)) +>f15 : Symbol(f15, Decl(genericRestParameters1.ts, 76, 1)) + +let x32 = callr(sn, f16); // string | number +>x32 : Symbol(x32, Decl(genericRestParameters1.ts, 89, 3)) +>callr : Symbol(callr, Decl(genericRestParameters1.ts, 72, 1)) +>sn : Symbol(sn, Decl(genericRestParameters1.ts, 12, 13)) +>f16 : Symbol(f16, Decl(genericRestParameters1.ts, 78, 60)) + +function bind(f: (x: T, ...rest: U) => V, x: T) { +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 91, 14)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 91, 16)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 91, 37)) +>f : Symbol(f, Decl(genericRestParameters1.ts, 91, 41)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 91, 45)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 91, 14)) +>rest : Symbol(rest, Decl(genericRestParameters1.ts, 91, 50)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 91, 16)) +>V : Symbol(V, Decl(genericRestParameters1.ts, 91, 37)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 91, 68)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 91, 14)) + + return (...rest: U) => f(x, ...rest); +>rest : Symbol(rest, Decl(genericRestParameters1.ts, 92, 12)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 91, 16)) +>f : Symbol(f, Decl(genericRestParameters1.ts, 91, 41)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 91, 68)) +>rest : Symbol(rest, Decl(genericRestParameters1.ts, 92, 12)) +} + +declare const f20: (x: number, y: string, z: boolean) => string[]; +>f20 : Symbol(f20, Decl(genericRestParameters1.ts, 95, 13)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 95, 20)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 95, 30)) +>z : Symbol(z, Decl(genericRestParameters1.ts, 95, 41)) + +const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] +>f21 : Symbol(f21, Decl(genericRestParameters1.ts, 97, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>f20 : Symbol(f20, Decl(genericRestParameters1.ts, 95, 13)) + +const f22 = bind(f21, "hello"); // (z: boolean) => string[] +>f22 : Symbol(f22, Decl(genericRestParameters1.ts, 98, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>f21 : Symbol(f21, Decl(genericRestParameters1.ts, 97, 5)) + +const f23 = bind(f22, true); // () => string[] +>f23 : Symbol(f23, Decl(genericRestParameters1.ts, 99, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>f22 : Symbol(f22, Decl(genericRestParameters1.ts, 98, 5)) + +f20(42, "hello", true); +>f20 : Symbol(f20, Decl(genericRestParameters1.ts, 95, 13)) + +f21("hello", true); +>f21 : Symbol(f21, Decl(genericRestParameters1.ts, 97, 5)) + +f22(true); +>f22 : Symbol(f22, Decl(genericRestParameters1.ts, 98, 5)) + +f23(); +>f23 : Symbol(f23, Decl(genericRestParameters1.ts, 99, 5)) + +declare const g20: (x: number, y?: string, z?: boolean) => string[]; +>g20 : Symbol(g20, Decl(genericRestParameters1.ts, 106, 13)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 106, 20)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 106, 30)) +>z : Symbol(z, Decl(genericRestParameters1.ts, 106, 42)) + +const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] +>g21 : Symbol(g21, Decl(genericRestParameters1.ts, 108, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>g20 : Symbol(g20, Decl(genericRestParameters1.ts, 106, 13)) + +const g22 = bind(g21, "hello"); // (z: boolean) => string[] +>g22 : Symbol(g22, Decl(genericRestParameters1.ts, 109, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>g21 : Symbol(g21, Decl(genericRestParameters1.ts, 108, 5)) + +const g23 = bind(g22, true); // () => string[] +>g23 : Symbol(g23, Decl(genericRestParameters1.ts, 110, 5)) +>bind : Symbol(bind, Decl(genericRestParameters1.ts, 89, 25)) +>g22 : Symbol(g22, Decl(genericRestParameters1.ts, 109, 5)) + +g20(42, "hello", true); +>g20 : Symbol(g20, Decl(genericRestParameters1.ts, 106, 13)) + +g20(42, "hello"); +>g20 : Symbol(g20, Decl(genericRestParameters1.ts, 106, 13)) + +g20(42); +>g20 : Symbol(g20, Decl(genericRestParameters1.ts, 106, 13)) + +g21("hello", true); +>g21 : Symbol(g21, Decl(genericRestParameters1.ts, 108, 5)) + +g21("hello"); +>g21 : Symbol(g21, Decl(genericRestParameters1.ts, 108, 5)) + +g21(); +>g21 : Symbol(g21, Decl(genericRestParameters1.ts, 108, 5)) + +g22(true); +>g22 : Symbol(g22, Decl(genericRestParameters1.ts, 109, 5)) + +g22(); +>g22 : Symbol(g22, Decl(genericRestParameters1.ts, 109, 5)) + +g23(); +>g23 : Symbol(g23, Decl(genericRestParameters1.ts, 110, 5)) + +declare function f30 any)[]>(x: T, ...args: U): U; +>f30 : Symbol(f30, Decl(genericRestParameters1.ts, 120, 6)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 122, 21)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 122, 23)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 122, 36)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 122, 21)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 122, 53)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 122, 21)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 122, 58)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 122, 23)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 122, 23)) + +const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] +>c30 : Symbol(c30, Decl(genericRestParameters1.ts, 124, 5)) +>f30 : Symbol(f30, Decl(genericRestParameters1.ts, 120, 6)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 124, 19)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 124, 19)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 124, 32)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 124, 32)) + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 126, 16)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 126, 16)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 126, 50)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 126, 64), Decl(genericRestParameters1.ts, 126, 97)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 126, 83)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 126, 64), Decl(genericRestParameters1.ts, 126, 97)) +>U : Symbol(U, Decl(genericRestParameters1.ts, 126, 64), Decl(genericRestParameters1.ts, 126, 97)) + +type T01 = Parameters<(x: number, y: string, z: boolean) => void>; +>T01 : Symbol(T01, Decl(genericRestParameters1.ts, 126, 121)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 128, 23)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 128, 33)) +>z : Symbol(z, Decl(genericRestParameters1.ts, 128, 44)) + +type T02 = Parameters<(...args: [number, string, boolean]) => void>; +>T02 : Symbol(T02, Decl(genericRestParameters1.ts, 128, 66)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 129, 23)) + +type T03 = Parameters void>; +>T03 : Symbol(T03, Decl(genericRestParameters1.ts, 129, 68)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>x : Symbol(x, Decl(genericRestParameters1.ts, 130, 27)) +>y : Symbol(y, Decl(genericRestParameters1.ts, 130, 37)) +>z : Symbol(z, Decl(genericRestParameters1.ts, 130, 48)) + +type T04 = Parameters void>; +>T04 : Symbol(T04, Decl(genericRestParameters1.ts, 130, 70)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 131, 27)) + +type T05 = Parameters<(...args: T[]) => void>; +>T05 : Symbol(T05, Decl(genericRestParameters1.ts, 131, 72)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 132, 9)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 132, 26)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 132, 9)) + +type T06 = Parameters void>; +>T06 : Symbol(T06, Decl(genericRestParameters1.ts, 132, 49)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 133, 9)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 133, 30)) + +type T07 = Parameters<(...args: T) => void>; +>T07 : Symbol(T07, Decl(genericRestParameters1.ts, 133, 52)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 134, 9)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 134, 40)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 134, 9)) + +type T08 = Parameters void>; +>T08 : Symbol(T08, Decl(genericRestParameters1.ts, 134, 61)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 135, 9)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>args : Symbol(args, Decl(genericRestParameters1.ts, 135, 44)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 135, 9)) + +type T09 = Parameters; +>T09 : Symbol(T09, Decl(genericRestParameters1.ts, 135, 65)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters1.ts, 124, 45)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +type Record1 = { +>Record1 : Symbol(Record1, Decl(genericRestParameters1.ts, 136, 32)) + + move: [number, 'left' | 'right']; +>move : Symbol(move, Decl(genericRestParameters1.ts, 138, 16)) + + jump: [number, 'up' | 'down']; +>jump : Symbol(jump, Decl(genericRestParameters1.ts, 139, 35)) + + stop: string; +>stop : Symbol(stop, Decl(genericRestParameters1.ts, 140, 32)) + + done: []; +>done : Symbol(done, Decl(genericRestParameters1.ts, 141, 15)) +} + +type EventType = { +>EventType : Symbol(EventType, Decl(genericRestParameters1.ts, 143, 1)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) + + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; +>emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) +>K : Symbol(K, Decl(genericRestParameters1.ts, 146, 7)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) +>e : Symbol(e, Decl(genericRestParameters1.ts, 146, 36)) +>K : Symbol(K, Decl(genericRestParameters1.ts, 146, 7)) +>payload : Symbol(payload, Decl(genericRestParameters1.ts, 146, 41)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) +>K : Symbol(K, Decl(genericRestParameters1.ts, 146, 7)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) +>K : Symbol(K, Decl(genericRestParameters1.ts, 146, 7)) +>T : Symbol(T, Decl(genericRestParameters1.ts, 145, 15)) +>K : Symbol(K, Decl(genericRestParameters1.ts, 146, 7)) +} + +declare var events: EventType; +>events : Symbol(events, Decl(genericRestParameters1.ts, 149, 11)) +>EventType : Symbol(EventType, Decl(genericRestParameters1.ts, 143, 1)) +>Record1 : Symbol(Record1, Decl(genericRestParameters1.ts, 136, 32)) + +events.emit('move', 10, 'left'); +>events.emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) +>events : Symbol(events, Decl(genericRestParameters1.ts, 149, 11)) +>emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) + +events.emit('jump', 20, 'up'); +>events.emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) +>events : Symbol(events, Decl(genericRestParameters1.ts, 149, 11)) +>emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) + +events.emit('stop', 'Bye!'); +>events.emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) +>events : Symbol(events, Decl(genericRestParameters1.ts, 149, 11)) +>emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) + +events.emit('done'); +>events.emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) +>events : Symbol(events, Decl(genericRestParameters1.ts, 149, 11)) +>emit : Symbol(emit, Decl(genericRestParameters1.ts, 145, 21)) + diff --git a/tests/baselines/reference/genericRestParameters1.types b/tests/baselines/reference/genericRestParameters1.types new file mode 100644 index 0000000000000..7fc8adefc97bb --- /dev/null +++ b/tests/baselines/reference/genericRestParameters1.types @@ -0,0 +1,851 @@ +=== tests/cases/conformance/types/rest/genericRestParameters1.ts === +declare let f1: (...x: [number, string, boolean]) => void; +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>x : [number, string, boolean] + +declare let f2: (x0: number, x1: string, x2: boolean) => void; +>f2 : (x0: number, x1: string, x2: boolean) => void +>x0 : number +>x1 : string +>x2 : boolean + +f1 = f2; +>f1 = f2 : (x0: number, x1: string, x2: boolean) => void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>f2 : (x0: number, x1: string, x2: boolean) => void + +f2 = f1; +>f2 = f1 : (x_0: number, x_1: string, x_2: boolean) => void +>f2 : (x0: number, x1: string, x2: boolean) => void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void + +declare const t3: [number, string, boolean]; +>t3 : [number, string, boolean] + +declare const t2: [string, boolean]; +>t2 : [string, boolean] + +declare const t1: [boolean]; +>t1 : [boolean] + +declare const t0: []; +>t0 : [] + +declare const ns: [number, string]; +>ns : [number, string] + +declare const sn: [string, number]; +>sn : [string, number] + +f1(42, "hello", true); +>f1(42, "hello", true) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f1(t3[0], t3[1], t3[2]); +>f1(t3[0], t3[1], t3[2]) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>t3[0] : number +>t3 : [number, string, boolean] +>0 : 0 +>t3[1] : string +>t3 : [number, string, boolean] +>1 : 1 +>t3[2] : boolean +>t3 : [number, string, boolean] +>2 : 2 + +f1(...t3); +>f1(...t3) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>...t3 : string | number | boolean +>t3 : [number, string, boolean] + +f1(42, ...t2); +>f1(42, ...t2) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, boolean] + +f1(42, "hello", ...t1); +>f1(42, "hello", ...t1) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>42 : 42 +>"hello" : "hello" +>...t1 : boolean +>t1 : [boolean] + +f1(42, "hello", true, ...t0); +>f1(42, "hello", true, ...t0) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t0 : never +>t0 : [] + +f1(ns[0], ns[1], true); +>f1(ns[0], ns[1], true) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>ns[0] : number +>ns : [number, string] +>0 : 0 +>ns[1] : string +>ns : [number, string] +>1 : 1 +>true : true + +f1(...ns, true); // Error, tuple spread only expanded when last +>f1(...ns, true) : void +>f1 : (x_0: number, x_1: string, x_2: boolean) => void +>...ns : string | number +>ns : [number, string] +>true : true + +f2(42, "hello", true); +>f2(42, "hello", true) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f2(t3[0], t3[1], t3[2]); +>f2(t3[0], t3[1], t3[2]) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>t3[0] : number +>t3 : [number, string, boolean] +>0 : 0 +>t3[1] : string +>t3 : [number, string, boolean] +>1 : 1 +>t3[2] : boolean +>t3 : [number, string, boolean] +>2 : 2 + +f2(...t3); +>f2(...t3) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>...t3 : string | number | boolean +>t3 : [number, string, boolean] + +f2(42, ...t2); +>f2(42, ...t2) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, boolean] + +f2(42, "hello", ...t1); +>f2(42, "hello", ...t1) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>42 : 42 +>"hello" : "hello" +>...t1 : boolean +>t1 : [boolean] + +f2(42, "hello", true, ...t0); +>f2(42, "hello", true, ...t0) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t0 : never +>t0 : [] + +f2(ns[0], ns[1], true); +>f2(ns[0], ns[1], true) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>ns[0] : number +>ns : [number, string] +>0 : 0 +>ns[1] : string +>ns : [number, string] +>1 : 1 +>true : true + +f2(...ns, true); // Error, tuple spread only expanded when last +>f2(...ns, true) : void +>f2 : (x0: number, x1: string, x2: boolean) => void +>...ns : string | number +>ns : [number, string] +>true : true + +declare function f10(...args: T): T; +>f10 : (...args: T) => T +>T : T +>args : T +>T : T +>T : T + +const x10 = f10(42, "hello", true); // [number, string, boolean] +>x10 : [number, string, boolean] +>f10(42, "hello", true) : [number, string, boolean] +>f10 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>true : true + +const x11 = f10(42, "hello"); // [number, string] +>x11 : [number, string] +>f10(42, "hello") : [number, string] +>f10 : (...args: T) => T +>42 : 42 +>"hello" : "hello" + +const x12 = f10(42); // [number] +>x12 : [number] +>f10(42) : [number] +>f10 : (...args: T) => T +>42 : 42 + +const x13 = f10(); // [] +>x13 : [] +>f10() : [] +>f10 : (...args: T) => T + +const x14 = f10(...t3); // [number, string, boolean] +>x14 : [number, string, boolean] +>f10(...t3) : [number, string, boolean] +>f10 : (...args: T) => T +>...t3 : string | number | boolean +>t3 : [number, string, boolean] + +const x15 = f10(42, ...t2); // [number, string, boolean] +>x15 : [number, string, boolean] +>f10(42, ...t2) : [number, string, boolean] +>f10 : (...args: T) => T +>42 : 42 +>...t2 : string | boolean +>t2 : [string, boolean] + +const x16 = f10(42, "hello", ...t1); // [number, string, boolean] +>x16 : [number, string, boolean] +>f10(42, "hello", ...t1) : [number, string, boolean] +>f10 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>...t1 : boolean +>t1 : [boolean] + +const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] +>x17 : [number, string, boolean] +>f10(42, "hello", true, ...t0) : [number, string, boolean] +>f10 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>true : true +>...t0 : never +>t0 : [] + +const x18 = f10(...ns, true); // (string | number | boolean)[] +>x18 : (string | number | boolean)[] +>f10(...ns, true) : (string | number | boolean)[] +>f10 : (...args: T) => T +>...ns : string | number +>ns : [number, string] +>true : true + +function g10(u: U, v: V) { +>g10 : (u: U, v: V) => void +>U : U +>V : V +>u : U +>U : U +>v : V +>V : V + + let x1 = f10(...u); // U +>x1 : U +>f10(...u) : U +>f10 : (...args: T) => T +>...u : string +>u : U + + let x2 = f10(...v); // V +>x2 : V +>f10(...v) : V +>f10 : (...args: T) => T +>...v : number +>v : V + + let x3 = f10(1, ...u); // [number, ...string[]] +>x3 : [number, ...string[]] +>f10(1, ...u) : [number, ...string[]] +>f10 : (...args: T) => T +>1 : 1 +>...u : string +>u : U + + let x4 = f10(...u, ...v); // (string | number)[] +>x4 : (string | number)[] +>f10(...u, ...v) : (string | number)[] +>f10 : (...args: T) => T +>...u : string +>u : U +>...v : number +>v : V +} + +declare function f11(...args: T): T; +>f11 : (...args: T) => T +>T : T +>args : T +>T : T +>T : T + +const z10 = f11(42, "hello", true); // [42, "hello", true] +>z10 : [42, "hello", true] +>f11(42, "hello", true) : [42, "hello", true] +>f11 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>true : true + +const z11 = f11(42, "hello"); // [42, "hello"] +>z11 : [42, "hello"] +>f11(42, "hello") : [42, "hello"] +>f11 : (...args: T) => T +>42 : 42 +>"hello" : "hello" + +const z12 = f11(42); // [42] +>z12 : [42] +>f11(42) : [42] +>f11 : (...args: T) => T +>42 : 42 + +const z13 = f11(); // [] +>z13 : [] +>f11() : [] +>f11 : (...args: T) => T + +const z14 = f11(...t3); // [number, string, boolean] +>z14 : [number, string, boolean] +>f11(...t3) : [number, string, boolean] +>f11 : (...args: T) => T +>...t3 : string | number | boolean +>t3 : [number, string, boolean] + +const z15 = f11(42, ...t2); // [42, string, boolean] +>z15 : [42, string, boolean] +>f11(42, ...t2) : [42, string, boolean] +>f11 : (...args: T) => T +>42 : 42 +>...t2 : string | boolean +>t2 : [string, boolean] + +const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] +>z16 : [42, "hello", boolean] +>f11(42, "hello", ...t1) : [42, "hello", boolean] +>f11 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>...t1 : boolean +>t1 : [boolean] + +const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] +>z17 : [42, "hello", true] +>f11(42, "hello", true, ...t0) : [42, "hello", true] +>f11 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>true : true +>...t0 : never +>t0 : [] + +const z18 = f11(...ns, true); // (string | number | true)[] +>z18 : (string | number | true)[] +>f11(...ns, true) : (string | number | true)[] +>f11 : (...args: T) => T +>...ns : string | number +>ns : [number, string] +>true : true + +function g11(u: U, v: V) { +>g11 : (u: U, v: V) => void +>U : U +>V : V +>u : U +>U : U +>v : V +>V : V + + let x1 = f11(...u); // U +>x1 : U +>f11(...u) : U +>f11 : (...args: T) => T +>...u : string +>u : U + + let x2 = f11(...v); // V +>x2 : V +>f11(...v) : V +>f11 : (...args: T) => T +>...v : number +>v : V + + let x3 = f11(1, ...u); // [1, ...string[]] +>x3 : [1, ...string[]] +>f11(1, ...u) : [1, ...string[]] +>f11 : (...args: T) => T +>1 : 1 +>...u : string +>u : U + + let x4 = f11(...u, ...v); // (string | number)[] +>x4 : (string | number)[] +>f11(...u, ...v) : (string | number)[] +>f11 : (...args: T) => T +>...u : string +>u : U +>...v : number +>v : V +} + +function call(f: (...args: T) => U, ...args: T) { +>call : (f: (...args: T) => U, ...args: T) => U +>T : T +>U : U +>f : (...args: T) => U +>args : T +>T : T +>U : U +>args : T +>T : T + + return f(...args); +>f(...args) : U +>f : (...args: T) => U +>...args : unknown +>args : T +} + +function callr(args: T, f: (...args: T) => U) { +>callr : (args: T, f: (...args: T) => U) => U +>T : T +>U : U +>args : T +>T : T +>f : (...args: T) => U +>args : T +>T : T +>U : U + + return f(...args); +>f(...args) : U +>f : (...args: T) => U +>...args : unknown +>args : T +} + +declare function f15(a: string, b: number): string | number; +>f15 : (a: string, b: number) => string | number +>a : string +>b : number + +declare function f16(a: A, b: B): A | B; +>f16 : (a: A, b: B) => A | B +>A : A +>B : B +>a : A +>A : A +>b : B +>B : B +>A : A +>B : B + +let x20 = call((x, y) => x + y, 10, 20); // number +>x20 : number +>call((x, y) => x + y, 10, 20) : number +>call : (f: (...args: T) => U, ...args: T) => U +>(x, y) => x + y : (x: number, y: number) => number +>x : number +>y : number +>x + y : number +>x : number +>y : number +>10 : 10 +>20 : 20 + +let x21 = call((x, y) => x + y, 10, "hello"); // string +>x21 : string +>call((x, y) => x + y, 10, "hello") : string +>call : (f: (...args: T) => U, ...args: T) => U +>(x, y) => x + y : (x: number, y: string) => string +>x : number +>y : string +>x + y : string +>x : number +>y : string +>10 : 10 +>"hello" : "hello" + +let x22 = call(f15, "hello", 42); // string | number +>x22 : string | number +>call(f15, "hello", 42) : string | number +>call : (f: (...args: T) => U, ...args: T) => U +>f15 : (a: string, b: number) => string | number +>"hello" : "hello" +>42 : 42 + +let x23 = call(f16, "hello", 42); // unknown +>x23 : unknown +>call(f16, "hello", 42) : unknown +>call : (f: (...args: T) => U, ...args: T) => U +>f16 : (a: A, b: B) => A | B +>"hello" : "hello" +>42 : 42 + +let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number +>x24 : string | number +>call<[string, number], string | number>(f16, "hello", 42) : string | number +>call : (f: (...args: T) => U, ...args: T) => U +>f16 : (a: A, b: B) => A | B +>"hello" : "hello" +>42 : 42 + +let x30 = callr(sn, (x, y) => x + y); // string +>x30 : string +>callr(sn, (x, y) => x + y) : string +>callr : (args: T, f: (...args: T) => U) => U +>sn : [string, number] +>(x, y) => x + y : (x: string, y: number) => string +>x : string +>y : number +>x + y : string +>x : string +>y : number + +let x31 = callr(sn, f15); // string | number +>x31 : string | number +>callr(sn, f15) : string | number +>callr : (args: T, f: (...args: T) => U) => U +>sn : [string, number] +>f15 : (a: string, b: number) => string | number + +let x32 = callr(sn, f16); // string | number +>x32 : string | number +>callr(sn, f16) : string | number +>callr : (args: T, f: (...args: T) => U) => U +>sn : [string, number] +>f16 : (a: A, b: B) => A | B + +function bind(f: (x: T, ...rest: U) => V, x: T) { +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>T : T +>U : U +>V : V +>f : (x: T, ...rest: U) => V +>x : T +>T : T +>rest : U +>U : U +>V : V +>x : T +>T : T + + return (...rest: U) => f(x, ...rest); +>(...rest: U) => f(x, ...rest) : (...rest: U) => V +>rest : U +>U : U +>f(x, ...rest) : V +>f : (x: T, ...rest: U) => V +>x : T +>...rest : unknown +>rest : U +} + +declare const f20: (x: number, y: string, z: boolean) => string[]; +>f20 : (x: number, y: string, z: boolean) => string[] +>x : number +>y : string +>z : boolean + +const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] +>f21 : (y: string, z: boolean) => string[] +>bind(f20, 42) : (y: string, z: boolean) => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>f20 : (x: number, y: string, z: boolean) => string[] +>42 : 42 + +const f22 = bind(f21, "hello"); // (z: boolean) => string[] +>f22 : (z: boolean) => string[] +>bind(f21, "hello") : (z: boolean) => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>f21 : (y: string, z: boolean) => string[] +>"hello" : "hello" + +const f23 = bind(f22, true); // () => string[] +>f23 : () => string[] +>bind(f22, true) : () => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>f22 : (z: boolean) => string[] +>true : true + +f20(42, "hello", true); +>f20(42, "hello", true) : string[] +>f20 : (x: number, y: string, z: boolean) => string[] +>42 : 42 +>"hello" : "hello" +>true : true + +f21("hello", true); +>f21("hello", true) : string[] +>f21 : (y: string, z: boolean) => string[] +>"hello" : "hello" +>true : true + +f22(true); +>f22(true) : string[] +>f22 : (z: boolean) => string[] +>true : true + +f23(); +>f23() : string[] +>f23 : () => string[] + +declare const g20: (x: number, y?: string, z?: boolean) => string[]; +>g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>x : number +>y : string | undefined +>z : boolean | undefined + +const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] +>g21 : (y?: string | undefined, z?: boolean | undefined) => string[] +>bind(g20, 42) : (y?: string | undefined, z?: boolean | undefined) => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>42 : 42 + +const g22 = bind(g21, "hello"); // (z: boolean) => string[] +>g22 : (z?: boolean | undefined) => string[] +>bind(g21, "hello") : (z?: boolean | undefined) => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>g21 : (y?: string | undefined, z?: boolean | undefined) => string[] +>"hello" : "hello" + +const g23 = bind(g22, true); // () => string[] +>g23 : () => string[] +>bind(g22, true) : () => string[] +>bind : (f: (x: T, ...rest: U) => V, x: T) => (...rest: U) => V +>g22 : (z?: boolean | undefined) => string[] +>true : true + +g20(42, "hello", true); +>g20(42, "hello", true) : string[] +>g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>42 : 42 +>"hello" : "hello" +>true : true + +g20(42, "hello"); +>g20(42, "hello") : string[] +>g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>42 : 42 +>"hello" : "hello" + +g20(42); +>g20(42) : string[] +>g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>42 : 42 + +g21("hello", true); +>g21("hello", true) : string[] +>g21 : (y?: string | undefined, z?: boolean | undefined) => string[] +>"hello" : "hello" +>true : true + +g21("hello"); +>g21("hello") : string[] +>g21 : (y?: string | undefined, z?: boolean | undefined) => string[] +>"hello" : "hello" + +g21(); +>g21() : string[] +>g21 : (y?: string | undefined, z?: boolean | undefined) => string[] + +g22(true); +>g22(true) : string[] +>g22 : (z?: boolean | undefined) => string[] +>true : true + +g22(); +>g22() : string[] +>g22 : (z?: boolean | undefined) => string[] + +g23(); +>g23() : string[] +>g23 : () => string[] + +declare function f30 any)[]>(x: T, ...args: U): U; +>f30 : any)[]>(x: T, ...args: U) => U +>T : T +>U : U +>x : T +>T : T +>x : T +>T : T +>args : U +>U : U +>U : U + +const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] +>c30 : [(x: number) => string, (x: number) => number] +>f30(42, x => "" + x, x => x + 1) : [(x: number) => string, (x: number) => number] +>f30 : any)[]>(x: T, ...args: U) => U +>42 : 42 +>x => "" + x : (x: number) => string +>x : number +>"" + x : string +>"" : "" +>x : number +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; +>Parameters : Parameters +>T : T +>Function : Function +>T : T +>args : U +>U : U +>args : U +>U : U +>U : U + +type T01 = Parameters<(x: number, y: string, z: boolean) => void>; +>T01 : [number, string, boolean] +>Parameters : Parameters +>x : number +>y : string +>z : boolean + +type T02 = Parameters<(...args: [number, string, boolean]) => void>; +>T02 : [number, string, boolean] +>Parameters : Parameters +>args : [number, string, boolean] + +type T03 = Parameters void>; +>T03 : [number, string, boolean] +>Parameters : Parameters +>x : number +>y : string +>z : boolean + +type T04 = Parameters void>; +>T04 : [number, string, boolean] +>Parameters : Parameters +>args : [number, string, boolean] + +type T05 = Parameters<(...args: T[]) => void>; +>T05 : T[] +>T : T +>Parameters : Parameters +>args : T[] +>T : T + +type T06 = Parameters void>; +>T06 : [] +>T : T +>Parameters : Parameters +>args : [] + +type T07 = Parameters<(...args: T) => void>; +>T07 : T +>T : T +>Parameters : Parameters +>args : T +>T : T + +type T08 = Parameters void>; +>T08 : T +>T : T +>Parameters : Parameters +>args : T +>T : T + +type T09 = Parameters; +>T09 : any[] +>Parameters : Parameters +>Function : Function + +type Record1 = { +>Record1 : Record1 + + move: [number, 'left' | 'right']; +>move : [number, "left" | "right"] + + jump: [number, 'up' | 'down']; +>jump : [number, "up" | "down"] + + stop: string; +>stop : string + + done: []; +>done : [] +} + +type EventType = { +>EventType : EventType +>T : T + + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; +>emit : (e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]) => void +>K : K +>T : T +>T : T +>e : K +>K : K +>payload : T[K] extends any[] ? T[K] : [T[K]] +>T : T +>K : K +>T : T +>K : K +>T : T +>K : K +} + +declare var events: EventType; +>events : EventType +>EventType : EventType +>Record1 : Record1 + +events.emit('move', 10, 'left'); +>events.emit('move', 10, 'left') : void +>events.emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>events : EventType +>emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>'move' : "move" +>10 : 10 +>'left' : "left" + +events.emit('jump', 20, 'up'); +>events.emit('jump', 20, 'up') : void +>events.emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>events : EventType +>emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>'jump' : "jump" +>20 : 20 +>'up' : "up" + +events.emit('stop', 'Bye!'); +>events.emit('stop', 'Bye!') : void +>events.emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>events : EventType +>emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>'stop' : "stop" +>'Bye!' : "Bye!" + +events.emit('done'); +>events.emit('done') : void +>events.emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>events : EventType +>emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void +>'done' : "done" + diff --git a/tests/baselines/reference/genericRestParameters2.js b/tests/baselines/reference/genericRestParameters2.js new file mode 100644 index 0000000000000..143a4a62f5253 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters2.js @@ -0,0 +1,158 @@ +//// [genericRestParameters2.ts] +declare const t1: [number, string, ...boolean[]]; +declare const t2: [string, ...boolean[]]; +declare const t3: [...boolean[]]; +declare const t4: []; + +declare let f00: (...x: [number, string, boolean]) => void; +declare let f01: (a: number, ...x: [string, boolean]) => void; +declare let f02: (a: number, b: string, ...x: [boolean]) => void; +declare let f03: (a: number, b: string, c: boolean) => void; +declare let f04: (a: number, b: string, c: boolean, ...x: []) => void; + +declare let f10: (...x: [number, string, ...boolean[]]) => void; +declare let f11: (a: number, ...x: [string, ...boolean[]]) => void; +declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void; +declare let f13: (a: number, b: string, ...c: boolean[]) => void; + +declare const ns: [number, string]; +declare const sn: [string, number]; + +f10(42, "hello"); +f10(42, "hello", true); +f10(42, "hello", true, false); +f10(t1[0], t1[1], t1[2], t1[3]); +f10(...t1); +f10(42, ...t2); +f10(42, "hello", ...t3); +f10(42, "hello", true, ...t4); +f10(42, "hello", true, ...t4, false, ...t3); + +f11(42, "hello"); +f11(42, "hello", true); +f11(42, "hello", true, false); +f11(t1[0], t1[1], t1[2], t1[3]); +f11(...t1); +f11(42, ...t2); +f11(42, "hello", ...t3); +f11(42, "hello", true, ...t4); +f11(42, "hello", true, ...t4, false, ...t3); + +f12(42, "hello"); +f12(42, "hello", true); +f12(42, "hello", true, false); +f12(t1[0], t1[1], t1[2], t1[3]); +f12(...t1); +f12(42, ...t2); +f12(42, "hello", ...t3); +f12(42, "hello", true, ...t4); +f12(42, "hello", true, ...t4, false, ...t3); + +f13(42, "hello"); +f13(42, "hello", true); +f13(42, "hello", true, false); +f13(t1[0], t1[1], t1[2], t1[3]); +f13(...t1); +f13(42, ...t2); +f13(42, "hello", ...t3); +f13(42, "hello", true, ...t4); +f13(42, "hello", true, ...t4, false, ...t3); + +declare const f20: (...args: T) => T; + +f20(...t1); +f20(42, ...t2); +f20(42, "hello", ...t3); +f20(42, "hello", ...t2, true); + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; + +type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>; +type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>; +type T03 = Parameters void>; +type T04 = Parameters void>; +type T05 = Parameters<(x: string, ...args: T) => void>; +type T06 = T05<[number, ...boolean[]]>; + +type P1 = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[]; + +type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>; +type T11 = P1<(...z: number[]) => void>; +type T12 = P1<(x: number, y: number) => void>; + + +//// [genericRestParameters2.js] +"use strict"; +f10(42, "hello"); +f10(42, "hello", true); +f10(42, "hello", true, false); +f10(t1[0], t1[1], t1[2], t1[3]); +f10.apply(void 0, t1); +f10.apply(void 0, [42].concat(t2)); +f10.apply(void 0, [42, "hello"].concat(t3)); +f10.apply(void 0, [42, "hello", true].concat(t4)); +f10.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f11(42, "hello"); +f11(42, "hello", true); +f11(42, "hello", true, false); +f11(t1[0], t1[1], t1[2], t1[3]); +f11.apply(void 0, t1); +f11.apply(void 0, [42].concat(t2)); +f11.apply(void 0, [42, "hello"].concat(t3)); +f11.apply(void 0, [42, "hello", true].concat(t4)); +f11.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f12(42, "hello"); +f12(42, "hello", true); +f12(42, "hello", true, false); +f12(t1[0], t1[1], t1[2], t1[3]); +f12.apply(void 0, t1); +f12.apply(void 0, [42].concat(t2)); +f12.apply(void 0, [42, "hello"].concat(t3)); +f12.apply(void 0, [42, "hello", true].concat(t4)); +f12.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f13(42, "hello"); +f13(42, "hello", true); +f13(42, "hello", true, false); +f13(t1[0], t1[1], t1[2], t1[3]); +f13.apply(void 0, t1); +f13.apply(void 0, [42].concat(t2)); +f13.apply(void 0, [42, "hello"].concat(t3)); +f13.apply(void 0, [42, "hello", true].concat(t4)); +f13.apply(void 0, [42, "hello", true].concat(t4, [false], t3)); +f20.apply(void 0, t1); +f20.apply(void 0, [42].concat(t2)); +f20.apply(void 0, [42, "hello"].concat(t3)); +f20.apply(void 0, [42, "hello"].concat(t2, [true])); + + +//// [genericRestParameters2.d.ts] +declare const t1: [number, string, ...boolean[]]; +declare const t2: [string, ...boolean[]]; +declare const t3: [...boolean[]]; +declare const t4: []; +declare let f00: (...x: [number, string, boolean]) => void; +declare let f01: (a: number, ...x: [string, boolean]) => void; +declare let f02: (a: number, b: string, ...x: [boolean]) => void; +declare let f03: (a: number, b: string, c: boolean) => void; +declare let f04: (a: number, b: string, c: boolean, ...x: []) => void; +declare let f10: (...x: [number, string, ...boolean[]]) => void; +declare let f11: (a: number, ...x: [string, ...boolean[]]) => void; +declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void; +declare let f13: (a: number, b: string, ...c: boolean[]) => void; +declare const ns: [number, string]; +declare const sn: [string, number]; +declare const f20: (...args: T) => T; +declare type Parameters = T extends ((...args: infer U) => any) | (new (...args: infer U) => any) ? U : any[]; +declare type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>; +declare type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>; +declare type T03 = Parameters void>; +declare type T04 = Parameters void>; +declare type T05 = Parameters<(x: string, ...args: T) => void>; +declare type T06 = T05<[number, ...boolean[]]>; +declare type P1 = T extends (head: infer A, ...tail: infer B) => any ? { + head: A; + tail: B; +} : any[]; +declare type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>; +declare type T11 = P1<(...z: number[]) => void>; +declare type T12 = P1<(x: number, y: number) => void>; diff --git a/tests/baselines/reference/genericRestParameters2.symbols b/tests/baselines/reference/genericRestParameters2.symbols new file mode 100644 index 0000000000000..164d08d132e28 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters2.symbols @@ -0,0 +1,326 @@ +=== tests/cases/conformance/types/rest/genericRestParameters2.ts === +declare const t1: [number, string, ...boolean[]]; +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +declare const t2: [string, ...boolean[]]; +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +declare const t3: [...boolean[]]; +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +declare const t4: []; +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) + +declare let f00: (...x: [number, string, boolean]) => void; +>f00 : Symbol(f00, Decl(genericRestParameters2.ts, 5, 11)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 5, 18)) + +declare let f01: (a: number, ...x: [string, boolean]) => void; +>f01 : Symbol(f01, Decl(genericRestParameters2.ts, 6, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 6, 18)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 6, 28)) + +declare let f02: (a: number, b: string, ...x: [boolean]) => void; +>f02 : Symbol(f02, Decl(genericRestParameters2.ts, 7, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 7, 18)) +>b : Symbol(b, Decl(genericRestParameters2.ts, 7, 28)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 7, 39)) + +declare let f03: (a: number, b: string, c: boolean) => void; +>f03 : Symbol(f03, Decl(genericRestParameters2.ts, 8, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 8, 18)) +>b : Symbol(b, Decl(genericRestParameters2.ts, 8, 28)) +>c : Symbol(c, Decl(genericRestParameters2.ts, 8, 39)) + +declare let f04: (a: number, b: string, c: boolean, ...x: []) => void; +>f04 : Symbol(f04, Decl(genericRestParameters2.ts, 9, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 9, 18)) +>b : Symbol(b, Decl(genericRestParameters2.ts, 9, 28)) +>c : Symbol(c, Decl(genericRestParameters2.ts, 9, 39)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 9, 51)) + +declare let f10: (...x: [number, string, ...boolean[]]) => void; +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 11, 18)) + +declare let f11: (a: number, ...x: [string, ...boolean[]]) => void; +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 12, 18)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 12, 28)) + +declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void; +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 13, 18)) +>b : Symbol(b, Decl(genericRestParameters2.ts, 13, 28)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 13, 39)) + +declare let f13: (a: number, b: string, ...c: boolean[]) => void; +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>a : Symbol(a, Decl(genericRestParameters2.ts, 14, 18)) +>b : Symbol(b, Decl(genericRestParameters2.ts, 14, 28)) +>c : Symbol(c, Decl(genericRestParameters2.ts, 14, 39)) + +declare const ns: [number, string]; +>ns : Symbol(ns, Decl(genericRestParameters2.ts, 16, 13)) + +declare const sn: [string, number]; +>sn : Symbol(sn, Decl(genericRestParameters2.ts, 17, 13)) + +f10(42, "hello"); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) + +f10(42, "hello", true); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) + +f10(42, "hello", true, false); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) + +f10(t1[0], t1[1], t1[2], t1[3]); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>0 : Symbol(0) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>1 : Symbol(1) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f10(...t1); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f10(42, ...t2); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +f10(42, "hello", ...t3); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f10(42, "hello", true, ...t4); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) + +f10(42, "hello", true, ...t4, false, ...t3); +>f10 : Symbol(f10, Decl(genericRestParameters2.ts, 11, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f11(42, "hello"); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) + +f11(42, "hello", true); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) + +f11(42, "hello", true, false); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) + +f11(t1[0], t1[1], t1[2], t1[3]); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>0 : Symbol(0) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>1 : Symbol(1) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f11(...t1); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f11(42, ...t2); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +f11(42, "hello", ...t3); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f11(42, "hello", true, ...t4); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) + +f11(42, "hello", true, ...t4, false, ...t3); +>f11 : Symbol(f11, Decl(genericRestParameters2.ts, 12, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f12(42, "hello"); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) + +f12(42, "hello", true); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) + +f12(42, "hello", true, false); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) + +f12(t1[0], t1[1], t1[2], t1[3]); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>0 : Symbol(0) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>1 : Symbol(1) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f12(...t1); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f12(42, ...t2); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +f12(42, "hello", ...t3); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f12(42, "hello", true, ...t4); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) + +f12(42, "hello", true, ...t4, false, ...t3); +>f12 : Symbol(f12, Decl(genericRestParameters2.ts, 13, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f13(42, "hello"); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) + +f13(42, "hello", true); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) + +f13(42, "hello", true, false); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) + +f13(t1[0], t1[1], t1[2], t1[3]); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>0 : Symbol(0) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>1 : Symbol(1) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f13(...t1); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f13(42, ...t2); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +f13(42, "hello", ...t3); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f13(42, "hello", true, ...t4); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) + +f13(42, "hello", true, ...t4, false, ...t3); +>f13 : Symbol(f13, Decl(genericRestParameters2.ts, 14, 11)) +>t4 : Symbol(t4, Decl(genericRestParameters2.ts, 3, 13)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +declare const f20: (...args: T) => T; +>f20 : Symbol(f20, Decl(genericRestParameters2.ts, 59, 13)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 59, 20)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 59, 41)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 59, 20)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 59, 20)) + +f20(...t1); +>f20 : Symbol(f20, Decl(genericRestParameters2.ts, 59, 13)) +>t1 : Symbol(t1, Decl(genericRestParameters2.ts, 0, 13)) + +f20(42, ...t2); +>f20 : Symbol(f20, Decl(genericRestParameters2.ts, 59, 13)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +f20(42, "hello", ...t3); +>f20 : Symbol(f20, Decl(genericRestParameters2.ts, 59, 13)) +>t3 : Symbol(t3, Decl(genericRestParameters2.ts, 2, 13)) + +f20(42, "hello", ...t2, true); +>f20 : Symbol(f20, Decl(genericRestParameters2.ts, 59, 13)) +>t2 : Symbol(t2, Decl(genericRestParameters2.ts, 1, 13)) + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 66, 16)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 66, 16)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 66, 50)) +>U : Symbol(U, Decl(genericRestParameters2.ts, 66, 64), Decl(genericRestParameters2.ts, 66, 97)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 66, 83)) +>U : Symbol(U, Decl(genericRestParameters2.ts, 66, 64), Decl(genericRestParameters2.ts, 66, 97)) +>U : Symbol(U, Decl(genericRestParameters2.ts, 66, 64), Decl(genericRestParameters2.ts, 66, 97)) + +type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>; +>T01 : Symbol(T01, Decl(genericRestParameters2.ts, 66, 121)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 68, 23)) +>y : Symbol(y, Decl(genericRestParameters2.ts, 68, 33)) +>z : Symbol(z, Decl(genericRestParameters2.ts, 68, 44)) + +type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>; +>T02 : Symbol(T02, Decl(genericRestParameters2.ts, 68, 71)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 69, 23)) + +type T03 = Parameters void>; +>T03 : Symbol(T03, Decl(genericRestParameters2.ts, 69, 73)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 70, 27)) +>y : Symbol(y, Decl(genericRestParameters2.ts, 70, 37)) +>z : Symbol(z, Decl(genericRestParameters2.ts, 70, 48)) + +type T04 = Parameters void>; +>T04 : Symbol(T04, Decl(genericRestParameters2.ts, 70, 75)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 71, 27)) + +type T05 = Parameters<(x: string, ...args: T) => void>; +>T05 : Symbol(T05, Decl(genericRestParameters2.ts, 71, 77)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 72, 9)) +>Parameters : Symbol(Parameters, Decl(genericRestParameters2.ts, 64, 30)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 72, 40)) +>args : Symbol(args, Decl(genericRestParameters2.ts, 72, 50)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 72, 9)) + +type T06 = T05<[number, ...boolean[]]>; +>T06 : Symbol(T06, Decl(genericRestParameters2.ts, 72, 72)) +>T05 : Symbol(T05, Decl(genericRestParameters2.ts, 71, 77)) + +type P1 = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[]; +>P1 : Symbol(P1, Decl(genericRestParameters2.ts, 73, 39)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 75, 8)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(genericRestParameters2.ts, 75, 8)) +>head : Symbol(head, Decl(genericRestParameters2.ts, 75, 41)) +>A : Symbol(A, Decl(genericRestParameters2.ts, 75, 52)) +>tail : Symbol(tail, Decl(genericRestParameters2.ts, 75, 55)) +>B : Symbol(B, Decl(genericRestParameters2.ts, 75, 70)) +>head : Symbol(head, Decl(genericRestParameters2.ts, 75, 84)) +>A : Symbol(A, Decl(genericRestParameters2.ts, 75, 52)) +>tail : Symbol(tail, Decl(genericRestParameters2.ts, 75, 93)) +>B : Symbol(B, Decl(genericRestParameters2.ts, 75, 70)) + +type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>; +>T10 : Symbol(T10, Decl(genericRestParameters2.ts, 75, 112)) +>P1 : Symbol(P1, Decl(genericRestParameters2.ts, 73, 39)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 77, 15)) +>y : Symbol(y, Decl(genericRestParameters2.ts, 77, 25)) +>z : Symbol(z, Decl(genericRestParameters2.ts, 77, 36)) + +type T11 = P1<(...z: number[]) => void>; +>T11 : Symbol(T11, Decl(genericRestParameters2.ts, 77, 63)) +>P1 : Symbol(P1, Decl(genericRestParameters2.ts, 73, 39)) +>z : Symbol(z, Decl(genericRestParameters2.ts, 78, 15)) + +type T12 = P1<(x: number, y: number) => void>; +>T12 : Symbol(T12, Decl(genericRestParameters2.ts, 78, 40)) +>P1 : Symbol(P1, Decl(genericRestParameters2.ts, 73, 39)) +>x : Symbol(x, Decl(genericRestParameters2.ts, 79, 15)) +>y : Symbol(y, Decl(genericRestParameters2.ts, 79, 25)) + diff --git a/tests/baselines/reference/genericRestParameters2.types b/tests/baselines/reference/genericRestParameters2.types new file mode 100644 index 0000000000000..4b7904ce1d524 --- /dev/null +++ b/tests/baselines/reference/genericRestParameters2.types @@ -0,0 +1,500 @@ +=== tests/cases/conformance/types/rest/genericRestParameters2.ts === +declare const t1: [number, string, ...boolean[]]; +>t1 : [number, string, ...boolean[]] + +declare const t2: [string, ...boolean[]]; +>t2 : [string, ...boolean[]] + +declare const t3: [...boolean[]]; +>t3 : boolean[] + +declare const t4: []; +>t4 : [] + +declare let f00: (...x: [number, string, boolean]) => void; +>f00 : (x_0: number, x_1: string, x_2: boolean) => void +>x : [number, string, boolean] + +declare let f01: (a: number, ...x: [string, boolean]) => void; +>f01 : (a: number, x_0: string, x_1: boolean) => void +>a : number +>x : [string, boolean] + +declare let f02: (a: number, b: string, ...x: [boolean]) => void; +>f02 : (a: number, b: string, x_0: boolean) => void +>a : number +>b : string +>x : [boolean] + +declare let f03: (a: number, b: string, c: boolean) => void; +>f03 : (a: number, b: string, c: boolean) => void +>a : number +>b : string +>c : boolean + +declare let f04: (a: number, b: string, c: boolean, ...x: []) => void; +>f04 : (a: number, b: string, c: boolean) => void +>a : number +>b : string +>c : boolean +>x : [] + +declare let f10: (...x: [number, string, ...boolean[]]) => void; +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>x : [number, string, ...boolean[]] + +declare let f11: (a: number, ...x: [string, ...boolean[]]) => void; +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>a : number +>x : [string, ...boolean[]] + +declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void; +>f12 : (a: number, b: string, ...x: boolean[]) => void +>a : number +>b : string +>x : boolean[] + +declare let f13: (a: number, b: string, ...c: boolean[]) => void; +>f13 : (a: number, b: string, ...c: boolean[]) => void +>a : number +>b : string +>c : boolean[] + +declare const ns: [number, string]; +>ns : [number, string] + +declare const sn: [string, number]; +>sn : [string, number] + +f10(42, "hello"); +>f10(42, "hello") : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" + +f10(42, "hello", true); +>f10(42, "hello", true) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f10(42, "hello", true, false); +>f10(42, "hello", true, false) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>false : false + +f10(t1[0], t1[1], t1[2], t1[3]); +>f10(t1[0], t1[1], t1[2], t1[3]) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>t1[0] : number +>t1 : [number, string, ...boolean[]] +>0 : 0 +>t1[1] : string +>t1 : [number, string, ...boolean[]] +>1 : 1 +>t1[2] : boolean +>t1 : [number, string, ...boolean[]] +>2 : 2 +>t1[3] : boolean +>t1 : [number, string, ...boolean[]] +>3 : 3 + +f10(...t1); +>f10(...t1) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>...t1 : string | number | boolean +>t1 : [number, string, ...boolean[]] + +f10(42, ...t2); +>f10(42, ...t2) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, ...boolean[]] + +f10(42, "hello", ...t3); +>f10(42, "hello", ...t3) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>...t3 : boolean +>t3 : boolean[] + +f10(42, "hello", true, ...t4); +>f10(42, "hello", true, ...t4) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] + +f10(42, "hello", true, ...t4, false, ...t3); +>f10(42, "hello", true, ...t4, false, ...t3) : void +>f10 : (x_0: number, x_1: string, ...x_2: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] +>false : false +>...t3 : boolean +>t3 : boolean[] + +f11(42, "hello"); +>f11(42, "hello") : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" + +f11(42, "hello", true); +>f11(42, "hello", true) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f11(42, "hello", true, false); +>f11(42, "hello", true, false) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>false : false + +f11(t1[0], t1[1], t1[2], t1[3]); +>f11(t1[0], t1[1], t1[2], t1[3]) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>t1[0] : number +>t1 : [number, string, ...boolean[]] +>0 : 0 +>t1[1] : string +>t1 : [number, string, ...boolean[]] +>1 : 1 +>t1[2] : boolean +>t1 : [number, string, ...boolean[]] +>2 : 2 +>t1[3] : boolean +>t1 : [number, string, ...boolean[]] +>3 : 3 + +f11(...t1); +>f11(...t1) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>...t1 : string | number | boolean +>t1 : [number, string, ...boolean[]] + +f11(42, ...t2); +>f11(42, ...t2) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, ...boolean[]] + +f11(42, "hello", ...t3); +>f11(42, "hello", ...t3) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>...t3 : boolean +>t3 : boolean[] + +f11(42, "hello", true, ...t4); +>f11(42, "hello", true, ...t4) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] + +f11(42, "hello", true, ...t4, false, ...t3); +>f11(42, "hello", true, ...t4, false, ...t3) : void +>f11 : (a: number, x_0: string, ...x_1: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] +>false : false +>...t3 : boolean +>t3 : boolean[] + +f12(42, "hello"); +>f12(42, "hello") : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" + +f12(42, "hello", true); +>f12(42, "hello", true) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f12(42, "hello", true, false); +>f12(42, "hello", true, false) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>false : false + +f12(t1[0], t1[1], t1[2], t1[3]); +>f12(t1[0], t1[1], t1[2], t1[3]) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>t1[0] : number +>t1 : [number, string, ...boolean[]] +>0 : 0 +>t1[1] : string +>t1 : [number, string, ...boolean[]] +>1 : 1 +>t1[2] : boolean +>t1 : [number, string, ...boolean[]] +>2 : 2 +>t1[3] : boolean +>t1 : [number, string, ...boolean[]] +>3 : 3 + +f12(...t1); +>f12(...t1) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>...t1 : string | number | boolean +>t1 : [number, string, ...boolean[]] + +f12(42, ...t2); +>f12(42, ...t2) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, ...boolean[]] + +f12(42, "hello", ...t3); +>f12(42, "hello", ...t3) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>...t3 : boolean +>t3 : boolean[] + +f12(42, "hello", true, ...t4); +>f12(42, "hello", true, ...t4) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] + +f12(42, "hello", true, ...t4, false, ...t3); +>f12(42, "hello", true, ...t4, false, ...t3) : void +>f12 : (a: number, b: string, ...x: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] +>false : false +>...t3 : boolean +>t3 : boolean[] + +f13(42, "hello"); +>f13(42, "hello") : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" + +f13(42, "hello", true); +>f13(42, "hello", true) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true + +f13(42, "hello", true, false); +>f13(42, "hello", true, false) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>false : false + +f13(t1[0], t1[1], t1[2], t1[3]); +>f13(t1[0], t1[1], t1[2], t1[3]) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>t1[0] : number +>t1 : [number, string, ...boolean[]] +>0 : 0 +>t1[1] : string +>t1 : [number, string, ...boolean[]] +>1 : 1 +>t1[2] : boolean +>t1 : [number, string, ...boolean[]] +>2 : 2 +>t1[3] : boolean +>t1 : [number, string, ...boolean[]] +>3 : 3 + +f13(...t1); +>f13(...t1) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>...t1 : string | number | boolean +>t1 : [number, string, ...boolean[]] + +f13(42, ...t2); +>f13(42, ...t2) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>...t2 : string | boolean +>t2 : [string, ...boolean[]] + +f13(42, "hello", ...t3); +>f13(42, "hello", ...t3) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>...t3 : boolean +>t3 : boolean[] + +f13(42, "hello", true, ...t4); +>f13(42, "hello", true, ...t4) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] + +f13(42, "hello", true, ...t4, false, ...t3); +>f13(42, "hello", true, ...t4, false, ...t3) : void +>f13 : (a: number, b: string, ...c: boolean[]) => void +>42 : 42 +>"hello" : "hello" +>true : true +>...t4 : never +>t4 : [] +>false : false +>...t3 : boolean +>t3 : boolean[] + +declare const f20: (...args: T) => T; +>f20 : (...args: T) => T +>T : T +>args : T +>T : T +>T : T + +f20(...t1); +>f20(...t1) : [number, string, ...boolean[]] +>f20 : (...args: T) => T +>...t1 : string | number | boolean +>t1 : [number, string, ...boolean[]] + +f20(42, ...t2); +>f20(42, ...t2) : [number, string, ...boolean[]] +>f20 : (...args: T) => T +>42 : 42 +>...t2 : string | boolean +>t2 : [string, ...boolean[]] + +f20(42, "hello", ...t3); +>f20(42, "hello", ...t3) : [number, string, ...boolean[]] +>f20 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>...t3 : boolean +>t3 : boolean[] + +f20(42, "hello", ...t2, true); +>f20(42, "hello", ...t2, true) : [number, string, ...(string | boolean)[]] +>f20 : (...args: T) => T +>42 : 42 +>"hello" : "hello" +>...t2 : string | boolean +>t2 : [string, ...boolean[]] +>true : true + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; +>Parameters : Parameters +>T : T +>Function : Function +>T : T +>args : U +>U : U +>args : U +>U : U +>U : U + +type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>; +>T01 : [number, string, ...boolean[]] +>Parameters : Parameters +>x : number +>y : string +>z : boolean[] + +type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>; +>T02 : [number, string, ...boolean[]] +>Parameters : Parameters +>args : [number, string, ...boolean[]] + +type T03 = Parameters void>; +>T03 : [number, string, ...boolean[]] +>Parameters : Parameters +>x : number +>y : string +>z : boolean[] + +type T04 = Parameters void>; +>T04 : [number, string, ...boolean[]] +>Parameters : Parameters +>args : [number, string, ...boolean[]] + +type T05 = Parameters<(x: string, ...args: T) => void>; +>T05 : Parameters<(x: string, ...args: T) => void> +>T : T +>Parameters : Parameters +>x : string +>args : T +>T : T + +type T06 = T05<[number, ...boolean[]]>; +>T06 : [string, number, ...boolean[]] +>T05 : Parameters<(x: string, ...args: T) => void> + +type P1 = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[]; +>P1 : P1 +>T : T +>Function : Function +>T : T +>head : A +>A : A +>tail : B +>B : B +>head : A +>A : A +>tail : B +>B : B + +type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>; +>T10 : { head: number; tail: [string, ...boolean[]]; } +>P1 : P1 +>x : number +>y : string +>z : boolean[] + +type T11 = P1<(...z: number[]) => void>; +>T11 : { head: number; tail: number[]; } +>P1 : P1 +>z : number[] + +type T12 = P1<(x: number, y: number) => void>; +>T12 : { head: number; tail: [number]; } +>P1 : P1 +>x : number +>y : number + diff --git a/tests/baselines/reference/initializedDestructuringAssignmentTypes.types b/tests/baselines/reference/initializedDestructuringAssignmentTypes.types index 55ddfa4f56b52..bb30a395cffa5 100644 --- a/tests/baselines/reference/initializedDestructuringAssignmentTypes.types +++ b/tests/baselines/reference/initializedDestructuringAssignmentTypes.types @@ -3,13 +3,13 @@ const [, a = ''] = ''.match('') || []; > : undefined >a : string >'' : "" ->''.match('') || [] : RegExpMatchArray | [undefined, ""] +>''.match('') || [] : RegExpMatchArray >''.match('') : RegExpMatchArray >''.match : (regexp: string | RegExp) => RegExpMatchArray >'' : "" >match : (regexp: string | RegExp) => RegExpMatchArray >'' : "" ->[] : [undefined, ""] +>[] : [undefined?, ""?] a.toFixed() >a.toFixed() : any diff --git a/tests/baselines/reference/iterableArrayPattern13.errors.txt b/tests/baselines/reference/iterableArrayPattern13.errors.txt new file mode 100644 index 0000000000000..54c064e9ffc94 --- /dev/null +++ b/tests/baselines/reference/iterableArrayPattern13.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/es6/destructuring/iterableArrayPattern13.ts(17,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, ...any[]]'. + Property '0' is missing in type 'FooIterator'. + + +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern13.ts (1 errors) ==== + class Bar { x } + class Foo extends Bar { y } + class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + + [Symbol.iterator]() { + return this; + } + } + + function fun([a, ...b]) { } + fun(new FooIterator); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, ...any[]]'. +!!! error TS2345: Property '0' is missing in type 'FooIterator'. \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern13.types b/tests/baselines/reference/iterableArrayPattern13.types index b97e955137208..d73f5cf0ab8de 100644 --- a/tests/baselines/reference/iterableArrayPattern13.types +++ b/tests/baselines/reference/iterableArrayPattern13.types @@ -41,13 +41,13 @@ class FooIterator { } function fun([a, ...b]) { } ->fun : ([a, ...b]: Iterable) => void +>fun : ([a, ...b]: [any, ...any[]]) => void >a : any >b : any[] fun(new FooIterator); >fun(new FooIterator) : void ->fun : ([a, ...b]: Iterable) => void +>fun : ([a, ...b]: [any, ...any[]]) => void >new FooIterator : FooIterator >FooIterator : typeof FooIterator diff --git a/tests/baselines/reference/iterableArrayPattern14.types b/tests/baselines/reference/iterableArrayPattern14.types index fcea515d543ec..b16b7e39c12cb 100644 --- a/tests/baselines/reference/iterableArrayPattern14.types +++ b/tests/baselines/reference/iterableArrayPattern14.types @@ -41,13 +41,13 @@ class FooIterator { } function fun(...[a, ...b]) { } ->fun : (...[a, ...b]: Iterable) => void +>fun : (__0_0: any, ...__0_1: any[]) => void >a : any >b : any[] fun(new FooIterator); >fun(new FooIterator) : void ->fun : (...[a, ...b]: Iterable) => void +>fun : (__0_0: any, ...__0_1: any[]) => void >new FooIterator : FooIterator >FooIterator : typeof FooIterator diff --git a/tests/baselines/reference/iterableArrayPattern24.types b/tests/baselines/reference/iterableArrayPattern24.types index ebcc055836e33..5a792a2f8516c 100644 --- a/tests/baselines/reference/iterableArrayPattern24.types +++ b/tests/baselines/reference/iterableArrayPattern24.types @@ -5,7 +5,7 @@ var a: string, b: boolean[]; [a, ...b] = { 0: "", 1: true }; >[a, ...b] = { 0: "", 1: true } : { 0: string; 1: true; } ->[a, ...b] : (string | boolean)[] +>[a, ...b] : [string, ...boolean[]] >a : string >...b : boolean >b : boolean[] diff --git a/tests/baselines/reference/iterableArrayPattern25.errors.txt b/tests/baselines/reference/iterableArrayPattern25.errors.txt index 07f46c0d49ee8..19f2dca07f392 100644 --- a/tests/baselines/reference/iterableArrayPattern25.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern25.errors.txt @@ -1,8 +1,11 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(2,1): error TS2554: Expected 2 arguments, but got 1. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (2 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { } ~~~~~~~~~~~~~~~~~~~~ !!! error TS2501: A rest element cannot contain a binding pattern. - takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); \ No newline at end of file + takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 2 arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern25.types b/tests/baselines/reference/iterableArrayPattern25.types index c9d94679603ff..6fe3412c01142 100644 --- a/tests/baselines/reference/iterableArrayPattern25.types +++ b/tests/baselines/reference/iterableArrayPattern25.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts === function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { } ->takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [[any, any], [any, any]]) => void +>takeFirstTwoEntries : (__0_0: [any, any], __0_1: [any, any]) => void >k1 : any >v1 : any >k2 : any @@ -8,7 +8,7 @@ function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { } takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); >takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])) : void ->takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [[any, any], [any, any]]) => void +>takeFirstTwoEntries : (__0_0: [any, any], __0_1: [any, any]) => void >new Map([["", 0], ["hello", 1]]) : Map >Map : MapConstructor >[["", 0], ["hello", 1]] : [string, number][] diff --git a/tests/baselines/reference/iterableArrayPattern4.types b/tests/baselines/reference/iterableArrayPattern4.types index 92d34c9a7dbbf..ece3b235dc437 100644 --- a/tests/baselines/reference/iterableArrayPattern4.types +++ b/tests/baselines/reference/iterableArrayPattern4.types @@ -48,7 +48,7 @@ var a: Bar, b: Bar[]; [a, ...b] = new FooIterator >[a, ...b] = new FooIterator : FooIterator ->[a, ...b] : Bar[] +>[a, ...b] : [Bar, ...Bar[]] >a : Bar >...b : Bar >b : Bar[] diff --git a/tests/baselines/reference/iterableArrayPattern6.types b/tests/baselines/reference/iterableArrayPattern6.types index 6e182385a81cd..c465c02ea4494 100644 --- a/tests/baselines/reference/iterableArrayPattern6.types +++ b/tests/baselines/reference/iterableArrayPattern6.types @@ -47,7 +47,7 @@ var a: Bar, b: string[]; [a, ...b] = new FooIterator; >[a, ...b] = new FooIterator : FooIterator ->[a, ...b] : (string | Bar)[] +>[a, ...b] : [Bar, ...string[]] >a : Bar >...b : string >b : string[] diff --git a/tests/baselines/reference/iterableArrayPattern8.types b/tests/baselines/reference/iterableArrayPattern8.types index 7d53628c82f34..7614b15b05494 100644 --- a/tests/baselines/reference/iterableArrayPattern8.types +++ b/tests/baselines/reference/iterableArrayPattern8.types @@ -47,7 +47,7 @@ var a: Bar, b: string; [a, ...b] = new FooIterator; >[a, ...b] = new FooIterator : FooIterator ->[a, ...b] : (string | Bar)[] +>[a, ...b] : [Bar, ...string[]] >a : Bar >...b : string >b : string diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index c74c90c510f1b..14cfbd1ceab29 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -15,7 +15,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(35,21): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(36,21): error TS2538: Type 'boolean' cannot be used as an index type. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(41,31): error TS2538: Type 'boolean' cannot be used as an index type. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(46,16): error TS2538: Type 'boolean' cannot be used as an index type. -tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(49,12): error TS1122: A tuple type element list cannot be empty. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(63,33): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. @@ -61,7 +60,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error Type 'T' is not assignable to type 'U'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (34 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (33 errors) ==== class Shape { name: string; width: number; @@ -145,8 +144,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error type T60 = {}["toString"]; type T61 = []["toString"]; - ~~ -!!! error TS1122: A tuple type element list cannot be empty. declare let cond: boolean; diff --git a/tests/baselines/reference/noImplicitAnyDestructuringParameterDeclaration.types b/tests/baselines/reference/noImplicitAnyDestructuringParameterDeclaration.types index 6b6149be67002..c0eef976c4dbc 100644 --- a/tests/baselines/reference/noImplicitAnyDestructuringParameterDeclaration.types +++ b/tests/baselines/reference/noImplicitAnyDestructuringParameterDeclaration.types @@ -7,7 +7,7 @@ function f1([a], {b}, c, d) { // error >d : any } function f2([a = undefined], {b = null}, c = undefined, d = null) { // error ->f2 : ([a]: [any], { b }: { b?: any; }, c?: any, d?: any) => void +>f2 : ([a]: [any?], { b }: { b?: any; }, c?: any, d?: any) => void >a : any >undefined : undefined >b : any diff --git a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.types b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.types index 01355600ff3dc..823af52080699 100644 --- a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.types +++ b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.types @@ -44,5 +44,5 @@ var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error var [a5 = undefined] = []; // error >a5 : any >undefined : undefined ->[] : [undefined] +>[] : [undefined?] diff --git a/tests/baselines/reference/objectRestAssignment.types b/tests/baselines/reference/objectRestAssignment.types index b51260736ade0..c0c84b6d5e349 100644 --- a/tests/baselines/reference/objectRestAssignment.types +++ b/tests/baselines/reference/objectRestAssignment.types @@ -59,9 +59,9 @@ var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; ({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); >({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit) : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } >{ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } ->{ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } : { ke: string; ko: string; a: { ka: string; x: string; }[]; b: { ki: string; ku: string; z: string; }; } ->a : { ka: string; x: string; }[] ->[{ ...nested2 }, ...y] : { ka: string; x: string; }[] +>{ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } : { ke: string; ko: string; a: [{ ka: string; x: string; }, ...{ ka: string; x: string; }[]]; b: { ki: string; ku: string; z: string; }; } +>a : [{ ka: string; x: string; }, ...{ ka: string; x: string; }[]] +>[{ ...nested2 }, ...y] : [{ ka: string; x: string; }, ...{ ka: string; x: string; }[]] >{ ...nested2 } : { ka: string; x: string; } >nested2 : { ka: string; x: string; } >...y : { ka: string; x: string; } diff --git a/tests/baselines/reference/optionalTupleElements1.errors.txt b/tests/baselines/reference/optionalTupleElements1.errors.txt new file mode 100644 index 0000000000000..ac9f5f244da2d --- /dev/null +++ b/tests/baselines/reference/optionalTupleElements1.errors.txt @@ -0,0 +1,105 @@ +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(11,29): error TS1257: A required element cannot follow an optional element. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(15,5): error TS2322: Type '[number, string, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. + Types of property '2' are incompatible. + Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(16,5): error TS2322: Type '[number, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. + Types of property '1' are incompatible. + Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(17,5): error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. + Types of property '0' are incompatible. + Type 'number | undefined' is not assignable to type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(20,5): error TS2322: Type '[number, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, (boolean | undefined)?]'. + Types of property '1' are incompatible. + Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(21,5): error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, (boolean | undefined)?]'. + Types of property '0' are incompatible. + Type 'number | undefined' is not assignable to type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/optionalTupleElements1.ts(25,5): error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, (string | undefined)?, (boolean | undefined)?]'. + Types of property '0' are incompatible. + Type 'number | undefined' is not assignable to type 'number'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/tuple/optionalTupleElements1.ts (7 errors) ==== + type T1 = [number, string, boolean]; + type T2 = [number, string, boolean?]; + type T3 = [number, string?, boolean?]; + type T4 = [number?, string?, boolean?]; + + type L1 = T1["length"]; + type L2 = T2["length"]; + type L3 = T3["length"]; + type L4 = T4["length"]; + + type T5 = [number, string?, boolean]; // Error + ~~~~~~~ +!!! error TS1257: A required element cannot follow an optional element. + + function f1(t1: T1, t2: T2, t3: T3, t4: T4) { + t1 = t1; + t1 = t2; // Error + ~~ +!!! error TS2322: Type '[number, string, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. +!!! error TS2322: Types of property '2' are incompatible. +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. + t1 = t3; // Error + ~~ +!!! error TS2322: Type '[number, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. +!!! error TS2322: Type 'undefined' is not assignable to type 'string'. + t1 = t4; // Error + ~~ +!!! error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, boolean]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'. +!!! error TS2322: Type 'undefined' is not assignable to type 'number'. + t2 = t1; + t2 = t2; + t2 = t3; // Error + ~~ +!!! error TS2322: Type '[number, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, (boolean | undefined)?]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. +!!! error TS2322: Type 'undefined' is not assignable to type 'string'. + t2 = t4; // Error + ~~ +!!! error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, string, (boolean | undefined)?]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'. +!!! error TS2322: Type 'undefined' is not assignable to type 'number'. + t3 = t1; + t3 = t2; + t3 = t3; + t3 = t4; // Error + ~~ +!!! error TS2322: Type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' is not assignable to type '[number, (string | undefined)?, (boolean | undefined)?]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'. +!!! error TS2322: Type 'undefined' is not assignable to type 'number'. + t4 = t1; + t4 = t2; + t4 = t3; + t4 = t4; + } + + let t2: T2; + let t3: T3; + let t4: T4; + + t2 = [42, "hello"]; + t3 = [42, "hello"]; + t3 = [42,,true] + t3 = [42]; + t4 = [42, "hello"]; + t4 = [42,,true]; + t4 = [,"hello", true]; + t4 = [,,true]; + t4 = []; + \ No newline at end of file diff --git a/tests/baselines/reference/optionalTupleElements1.js b/tests/baselines/reference/optionalTupleElements1.js new file mode 100644 index 0000000000000..73d3f616aa7c4 --- /dev/null +++ b/tests/baselines/reference/optionalTupleElements1.js @@ -0,0 +1,95 @@ +//// [optionalTupleElements1.ts] +type T1 = [number, string, boolean]; +type T2 = [number, string, boolean?]; +type T3 = [number, string?, boolean?]; +type T4 = [number?, string?, boolean?]; + +type L1 = T1["length"]; +type L2 = T2["length"]; +type L3 = T3["length"]; +type L4 = T4["length"]; + +type T5 = [number, string?, boolean]; // Error + +function f1(t1: T1, t2: T2, t3: T3, t4: T4) { + t1 = t1; + t1 = t2; // Error + t1 = t3; // Error + t1 = t4; // Error + t2 = t1; + t2 = t2; + t2 = t3; // Error + t2 = t4; // Error + t3 = t1; + t3 = t2; + t3 = t3; + t3 = t4; // Error + t4 = t1; + t4 = t2; + t4 = t3; + t4 = t4; +} + +let t2: T2; +let t3: T3; +let t4: T4; + +t2 = [42, "hello"]; +t3 = [42, "hello"]; +t3 = [42,,true] +t3 = [42]; +t4 = [42, "hello"]; +t4 = [42,,true]; +t4 = [,"hello", true]; +t4 = [,,true]; +t4 = []; + + +//// [optionalTupleElements1.js] +"use strict"; +function f1(t1, t2, t3, t4) { + t1 = t1; + t1 = t2; // Error + t1 = t3; // Error + t1 = t4; // Error + t2 = t1; + t2 = t2; + t2 = t3; // Error + t2 = t4; // Error + t3 = t1; + t3 = t2; + t3 = t3; + t3 = t4; // Error + t4 = t1; + t4 = t2; + t4 = t3; + t4 = t4; +} +var t2; +var t3; +var t4; +t2 = [42, "hello"]; +t3 = [42, "hello"]; +t3 = [42, , true]; +t3 = [42]; +t4 = [42, "hello"]; +t4 = [42, , true]; +t4 = [, "hello", true]; +t4 = [, , true]; +t4 = []; + + +//// [optionalTupleElements1.d.ts] +declare type T1 = [number, string, boolean]; +declare type T2 = [number, string, boolean?]; +declare type T3 = [number, string?, boolean?]; +declare type T4 = [number?, string?, boolean?]; +declare type L1 = T1["length"]; +declare type L2 = T2["length"]; +declare type L3 = T3["length"]; +declare type L4 = T4["length"]; +declare type T5 = [number, string?, boolean]; +declare function f1(t1: T1, t2: T2, t3: T3, t4: T4): void; +declare let t2: T2; +declare let t3: T3; +declare let t4: T4; diff --git a/tests/baselines/reference/optionalTupleElements1.symbols b/tests/baselines/reference/optionalTupleElements1.symbols new file mode 100644 index 0000000000000..e70d69b768a3f --- /dev/null +++ b/tests/baselines/reference/optionalTupleElements1.symbols @@ -0,0 +1,147 @@ +=== tests/cases/conformance/types/tuple/optionalTupleElements1.ts === +type T1 = [number, string, boolean]; +>T1 : Symbol(T1, Decl(optionalTupleElements1.ts, 0, 0)) + +type T2 = [number, string, boolean?]; +>T2 : Symbol(T2, Decl(optionalTupleElements1.ts, 0, 36)) + +type T3 = [number, string?, boolean?]; +>T3 : Symbol(T3, Decl(optionalTupleElements1.ts, 1, 37)) + +type T4 = [number?, string?, boolean?]; +>T4 : Symbol(T4, Decl(optionalTupleElements1.ts, 2, 38)) + +type L1 = T1["length"]; +>L1 : Symbol(L1, Decl(optionalTupleElements1.ts, 3, 39)) +>T1 : Symbol(T1, Decl(optionalTupleElements1.ts, 0, 0)) + +type L2 = T2["length"]; +>L2 : Symbol(L2, Decl(optionalTupleElements1.ts, 5, 23)) +>T2 : Symbol(T2, Decl(optionalTupleElements1.ts, 0, 36)) + +type L3 = T3["length"]; +>L3 : Symbol(L3, Decl(optionalTupleElements1.ts, 6, 23)) +>T3 : Symbol(T3, Decl(optionalTupleElements1.ts, 1, 37)) + +type L4 = T4["length"]; +>L4 : Symbol(L4, Decl(optionalTupleElements1.ts, 7, 23)) +>T4 : Symbol(T4, Decl(optionalTupleElements1.ts, 2, 38)) + +type T5 = [number, string?, boolean]; // Error +>T5 : Symbol(T5, Decl(optionalTupleElements1.ts, 8, 23)) + +function f1(t1: T1, t2: T2, t3: T3, t4: T4) { +>f1 : Symbol(f1, Decl(optionalTupleElements1.ts, 10, 37)) +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) +>T1 : Symbol(T1, Decl(optionalTupleElements1.ts, 0, 0)) +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) +>T2 : Symbol(T2, Decl(optionalTupleElements1.ts, 0, 36)) +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) +>T3 : Symbol(T3, Decl(optionalTupleElements1.ts, 1, 37)) +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +>T4 : Symbol(T4, Decl(optionalTupleElements1.ts, 2, 38)) + + t1 = t1; +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) + + t1 = t2; // Error +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) + + t1 = t3; // Error +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) + + t1 = t4; // Error +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) + + t2 = t1; +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) + + t2 = t2; +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) + + t2 = t3; // Error +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) + + t2 = t4; // Error +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) + + t3 = t1; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) + + t3 = t2; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) + + t3 = t3; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) + + t3 = t4; // Error +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) + + t4 = t1; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +>t1 : Symbol(t1, Decl(optionalTupleElements1.ts, 12, 12)) + + t4 = t2; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 12, 19)) + + t4 = t3; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 12, 27)) + + t4 = t4; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 12, 35)) +} + +let t2: T2; +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 31, 3)) +>T2 : Symbol(T2, Decl(optionalTupleElements1.ts, 0, 36)) + +let t3: T3; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 32, 3)) +>T3 : Symbol(T3, Decl(optionalTupleElements1.ts, 1, 37)) + +let t4: T4; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) +>T4 : Symbol(T4, Decl(optionalTupleElements1.ts, 2, 38)) + +t2 = [42, "hello"]; +>t2 : Symbol(t2, Decl(optionalTupleElements1.ts, 31, 3)) + +t3 = [42, "hello"]; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 32, 3)) + +t3 = [42,,true] +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 32, 3)) + +t3 = [42]; +>t3 : Symbol(t3, Decl(optionalTupleElements1.ts, 32, 3)) + +t4 = [42, "hello"]; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) + +t4 = [42,,true]; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) + +t4 = [,"hello", true]; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) + +t4 = [,,true]; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) + +t4 = []; +>t4 : Symbol(t4, Decl(optionalTupleElements1.ts, 33, 3)) + diff --git a/tests/baselines/reference/optionalTupleElements1.types b/tests/baselines/reference/optionalTupleElements1.types new file mode 100644 index 0000000000000..fa09afab3f0dc --- /dev/null +++ b/tests/baselines/reference/optionalTupleElements1.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/types/tuple/optionalTupleElements1.ts === +type T1 = [number, string, boolean]; +>T1 : [number, string, boolean] + +type T2 = [number, string, boolean?]; +>T2 : [number, string, (boolean | undefined)?] + +type T3 = [number, string?, boolean?]; +>T3 : [number, (string | undefined)?, (boolean | undefined)?] + +type T4 = [number?, string?, boolean?]; +>T4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + +type L1 = T1["length"]; +>L1 : 3 +>T1 : [number, string, boolean] + +type L2 = T2["length"]; +>L2 : 3 | 2 +>T2 : [number, string, (boolean | undefined)?] + +type L3 = T3["length"]; +>L3 : 3 | 2 | 1 +>T3 : [number, (string | undefined)?, (boolean | undefined)?] + +type L4 = T4["length"]; +>L4 : 0 | 3 | 2 | 1 +>T4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + +type T5 = [number, string?, boolean]; // Error +>T5 : [number, string | undefined, boolean] + +function f1(t1: T1, t2: T2, t3: T3, t4: T4) { +>f1 : (t1: [number, string, boolean], t2: [number, string, (boolean | undefined)?], t3: [number, (string | undefined)?, (boolean | undefined)?], t4: [(number | undefined)?, (string | undefined)?, (boolean | undefined)?]) => void +>t1 : [number, string, boolean] +>T1 : [number, string, boolean] +>t2 : [number, string, (boolean | undefined)?] +>T2 : [number, string, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>T3 : [number, (string | undefined)?, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>T4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + + t1 = t1; +>t1 = t1 : [number, string, boolean] +>t1 : [number, string, boolean] +>t1 : [number, string, boolean] + + t1 = t2; // Error +>t1 = t2 : [number, string, (boolean | undefined)?] +>t1 : [number, string, boolean] +>t2 : [number, string, (boolean | undefined)?] + + t1 = t3; // Error +>t1 = t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t1 : [number, string, boolean] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] + + t1 = t4; // Error +>t1 = t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t1 : [number, string, boolean] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + + t2 = t1; +>t2 = t1 : [number, string, boolean] +>t2 : [number, string, (boolean | undefined)?] +>t1 : [number, string, boolean] + + t2 = t2; +>t2 = t2 : [number, string, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] + + t2 = t3; // Error +>t2 = t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] + + t2 = t4; // Error +>t2 = t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + + t3 = t1; +>t3 = t1 : [number, string, boolean] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t1 : [number, string, boolean] + + t3 = t2; +>t3 = t2 : [number, string, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] + + t3 = t3; +>t3 = t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] + + t3 = t4; // Error +>t3 = t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + + t4 = t1; +>t4 = t1 : [number, string, boolean] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t1 : [number, string, boolean] + + t4 = t2; +>t4 = t2 : [number, string, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t2 : [number, string, (boolean | undefined)?] + + t4 = t3; +>t4 = t3 : [number, (string | undefined)?, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] + + t4 = t4; +>t4 = t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +} + +let t2: T2; +>t2 : [number, string, (boolean | undefined)?] +>T2 : [number, string, (boolean | undefined)?] + +let t3: T3; +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>T3 : [number, (string | undefined)?, (boolean | undefined)?] + +let t4: T4; +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>T4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] + +t2 = [42, "hello"]; +>t2 = [42, "hello"] : [number, string] +>t2 : [number, string, (boolean | undefined)?] +>[42, "hello"] : [number, string] +>42 : 42 +>"hello" : "hello" + +t3 = [42, "hello"]; +>t3 = [42, "hello"] : [number, string] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>[42, "hello"] : [number, string] +>42 : 42 +>"hello" : "hello" + +t3 = [42,,true] +>t3 = [42,,true] : [number, undefined, true] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>[42,,true] : [number, undefined, true] +>42 : 42 +> : undefined +>true : true + +t3 = [42]; +>t3 = [42] : [number] +>t3 : [number, (string | undefined)?, (boolean | undefined)?] +>[42] : [number] +>42 : 42 + +t4 = [42, "hello"]; +>t4 = [42, "hello"] : [number, string] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>[42, "hello"] : [number, string] +>42 : 42 +>"hello" : "hello" + +t4 = [42,,true]; +>t4 = [42,,true] : [number, undefined, true] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>[42,,true] : [number, undefined, true] +>42 : 42 +> : undefined +>true : true + +t4 = [,"hello", true]; +>t4 = [,"hello", true] : [undefined, string, true] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>[,"hello", true] : [undefined, string, true] +> : undefined +>"hello" : "hello" +>true : true + +t4 = [,,true]; +>t4 = [,,true] : [undefined, undefined, true] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>[,,true] : [undefined, undefined, true] +> : undefined +> : undefined +>true : true + +t4 = []; +>t4 = [] : [] +>t4 : [(number | undefined)?, (string | undefined)?, (boolean | undefined)?] +>[] : [] + diff --git a/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt b/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt index 73d768ddfeb71..77e78a676b406 100644 --- a/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt +++ b/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/promiseEmptyTupleNoException.ts(1,38): error TS1122: A tuple type element list cannot be empty. tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'. Types of property 'length' are incompatible. Type 'number' is not assignable to type '0'. -==== tests/cases/compiler/promiseEmptyTupleNoException.ts (2 errors) ==== +==== tests/cases/compiler/promiseEmptyTupleNoException.ts (1 errors) ==== export async function get(): Promise<[]> { - ~~ -!!! error TS1122: A tuple type element list cannot be empty. let emails = []; return emails; ~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/recursiveLetConst.types b/tests/baselines/reference/recursiveLetConst.types index 42db1d5df2464..7e4db6687aab1 100644 --- a/tests/baselines/reference/recursiveLetConst.types +++ b/tests/baselines/reference/recursiveLetConst.types @@ -49,7 +49,7 @@ for (let [v] of v) { } let [x2 = x2] = [] >x2 : any >x2 : any ->[] : [any] +>[] : [any?] let z0 = () => z0; >z0 : () => any diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.types b/tests/baselines/reference/restParameterWithBindingPattern2.types index 36465495b3650..7f46273a4972e 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern2.types +++ b/tests/baselines/reference/restParameterWithBindingPattern2.types @@ -1,6 +1,6 @@ === tests/cases/compiler/restParameterWithBindingPattern2.ts === function a(...[a, b]) { } ->a : (...[a, b]: [any, any]) => void +>a : (__0_0: any, __0_1: any) => void >a : any >b : any diff --git a/tests/baselines/reference/restTupleElements1.errors.txt b/tests/baselines/reference/restTupleElements1.errors.txt new file mode 100644 index 0000000000000..dbabfbe640e24 --- /dev/null +++ b/tests/baselines/reference/restTupleElements1.errors.txt @@ -0,0 +1,138 @@ +tests/cases/conformance/types/tuple/restTupleElements1.ts(3,22): error TS1257: A required element cannot follow an optional element. +tests/cases/conformance/types/tuple/restTupleElements1.ts(8,13): error TS1256: A rest element must be last in a tuple type. +tests/cases/conformance/types/tuple/restTupleElements1.ts(9,13): error TS2574: A rest element type must be an array type. +tests/cases/conformance/types/tuple/restTupleElements1.ts(10,13): error TS2574: A rest element type must be an array type. +tests/cases/conformance/types/tuple/restTupleElements1.ts(10,16): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/conformance/types/tuple/restTupleElements1.ts(23,31): error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(24,31): error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'. + Property '0' is missing in type '[]'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(29,18): error TS2344: Type 'number[]' does not satisfy the constraint '[number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(30,18): error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'. + Types of property 'length' are incompatible. + Type 'number' is not assignable to type '1'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(32,31): error TS2344: Type '[number, ...string[]]' does not satisfy the constraint '[number, ...number[]]'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(33,31): error TS2344: Type '[string, ...number[]]' does not satisfy the constraint '[number, ...number[]]'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(34,31): error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'. + Property '2' is incompatible with rest element type. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(35,31): error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'. + Property '3' is incompatible with rest element type. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: Argument of type '[]' is not assignable to parameter of type '[{}, ...{}[]]'. + Property '0' is missing in type '[]'. + + +==== tests/cases/conformance/types/tuple/restTupleElements1.ts (14 errors) ==== + type T00 = [string?]; + type T01 = [string, string?]; + type T02 = [string?, string]; // Error + ~~~~~~ +!!! error TS1257: A required element cannot follow an optional element. + type T03 = [...string[]]; + type T04 = [...[...string[]]]; + type T05 = [...[...[...string[]]]]; + type T06 = [string, ...string[]]; + type T07 = [...string[], string]; // Error + ~~~~~~~~~~~ +!!! error TS1256: A rest element must be last in a tuple type. + type T08 = [...string]; // Error + ~~~~~~~~~ +!!! error TS2574: A rest element type must be an array type. + type T09 = [...string?]; // Error + ~~~~~~~~~~ +!!! error TS2574: A rest element type must be an array type. + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type T10 = [string, ...[...string[]]]; + type T11 = [string, ...[...[...string[]]]]; + + type T15 = [boolean, number, ...string[]]; + type L15 = T15["length"]; // number + + declare function assign(): void; + + assign(); + assign(); + assign<[...number[]], number[]>(); + + assign<[number, ...number[]], number[]>(); // Error + ~~~~~~~~ +!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Property '0' is missing in type 'number[]'. + assign<[number, ...number[]], []>(); // Error + ~~ +!!! error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Property '0' is missing in type '[]'. + assign<[number, ...number[]], [number]>(); + assign<[number, ...number[]], [number, number]>(); + assign<[number, ...number[]], [number, number, ...number[]]>(); + + assign<[number], [...number[]]>(); // Error + ~~~~~~~~~~~~~ +!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number]'. +!!! error TS2344: Property '0' is missing in type 'number[]'. + assign<[number], [number, ...number[]]>(); // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'. +!!! error TS2344: Types of property 'length' are incompatible. +!!! error TS2344: Type 'number' is not assignable to type '1'. + + assign<[number, ...number[]], [number, ...string[]]>(); // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '[number, ...string[]]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Type 'string' is not assignable to type 'number'. + assign<[number, ...number[]], [string, ...number[]]>(); // Error + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '[string, ...number[]]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Type 'string' is not assignable to type 'number'. + assign<[number, ...number[]], [number, number, string]>(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Property '2' is incompatible with rest element type. +!!! error TS2344: Type 'string' is not assignable to type 'number'. + assign<[number, ...number[]], [number, number, number, string]>(); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'. +!!! error TS2344: Property '3' is incompatible with rest element type. +!!! error TS2344: Type 'string' is not assignable to type 'number'. + + type T20 = [number, string, ...boolean[]]; + + type T21 = T20[0]; + type T22 = T20[0 | 1]; + type T23 = T20[0 | 1 | 2]; + type T24 = T20[0 | 1 | 2 | 3]; + type T25 = T20[1 | 2 | 3]; + type T26 = T20[2 | 3]; + type T27 = T20[3]; + type T28 = T20[number]; + + declare const t: T20; + declare const x: number; + + let e0 = t[0]; // number + let e1 = t[1]; // string + let e2 = t[2]; // boolean + let e3 = t[3]; // boolean + let ex = t[x]; // number | string | boolean + + declare function f0(x: [T, ...U[]]): [T, U]; + + f0([]); // Error + ~~ +!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[{}, ...{}[]]'. +!!! error TS2345: Property '0' is missing in type '[]'. + f0([1]); + f0([1, 2, 3]); + f0([1, "hello", true]); + + declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; + declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; + + f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]); + f2(x => x * 2, x => x.length, x => x.charCodeAt(0)); + \ No newline at end of file diff --git a/tests/baselines/reference/restTupleElements1.js b/tests/baselines/reference/restTupleElements1.js new file mode 100644 index 0000000000000..a15c7fd4dd119 --- /dev/null +++ b/tests/baselines/reference/restTupleElements1.js @@ -0,0 +1,135 @@ +//// [restTupleElements1.ts] +type T00 = [string?]; +type T01 = [string, string?]; +type T02 = [string?, string]; // Error +type T03 = [...string[]]; +type T04 = [...[...string[]]]; +type T05 = [...[...[...string[]]]]; +type T06 = [string, ...string[]]; +type T07 = [...string[], string]; // Error +type T08 = [...string]; // Error +type T09 = [...string?]; // Error +type T10 = [string, ...[...string[]]]; +type T11 = [string, ...[...[...string[]]]]; + +type T15 = [boolean, number, ...string[]]; +type L15 = T15["length"]; // number + +declare function assign(): void; + +assign(); +assign(); +assign<[...number[]], number[]>(); + +assign<[number, ...number[]], number[]>(); // Error +assign<[number, ...number[]], []>(); // Error +assign<[number, ...number[]], [number]>(); +assign<[number, ...number[]], [number, number]>(); +assign<[number, ...number[]], [number, number, ...number[]]>(); + +assign<[number], [...number[]]>(); // Error +assign<[number], [number, ...number[]]>(); // Error + +assign<[number, ...number[]], [number, ...string[]]>(); // Error +assign<[number, ...number[]], [string, ...number[]]>(); // Error +assign<[number, ...number[]], [number, number, string]>(); // Error +assign<[number, ...number[]], [number, number, number, string]>(); // Error + +type T20 = [number, string, ...boolean[]]; + +type T21 = T20[0]; +type T22 = T20[0 | 1]; +type T23 = T20[0 | 1 | 2]; +type T24 = T20[0 | 1 | 2 | 3]; +type T25 = T20[1 | 2 | 3]; +type T26 = T20[2 | 3]; +type T27 = T20[3]; +type T28 = T20[number]; + +declare const t: T20; +declare const x: number; + +let e0 = t[0]; // number +let e1 = t[1]; // string +let e2 = t[2]; // boolean +let e3 = t[3]; // boolean +let ex = t[x]; // number | string | boolean + +declare function f0(x: [T, ...U[]]): [T, U]; + +f0([]); // Error +f0([1]); +f0([1, 2, 3]); +f0([1, "hello", true]); + +declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; +declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; + +f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]); +f2(x => x * 2, x => x.length, x => x.charCodeAt(0)); + + +//// [restTupleElements1.js] +"use strict"; +assign(); +assign(); +assign(); +assign(); // Error +assign(); // Error +assign(); +assign(); +assign(); +assign(); // Error +assign(); // Error +assign(); // Error +assign(); // Error +assign(); // Error +assign(); // Error +var e0 = t[0]; // number +var e1 = t[1]; // string +var e2 = t[2]; // boolean +var e3 = t[3]; // boolean +var ex = t[x]; // number | string | boolean +f0([]); // Error +f0([1]); +f0([1, 2, 3]); +f0([1, "hello", true]); +f1([function (x) { return x * 2; }, function (x) { return x.length; }, function (x) { return x.charCodeAt(0); }]); +f2(function (x) { return x * 2; }, function (x) { return x.length; }, function (x) { return x.charCodeAt(0); }); + + +//// [restTupleElements1.d.ts] +declare type T00 = [string?]; +declare type T01 = [string, string?]; +declare type T02 = [string?, string]; +declare type T03 = [...string[]]; +declare type T04 = [...[...string[]]]; +declare type T05 = [...[...[...string[]]]]; +declare type T06 = [string, ...string[]]; +declare type T07 = [...string[], string]; +declare type T08 = [...string]; +declare type T09 = [...?string]; +declare type T10 = [string, ...[...string[]]]; +declare type T11 = [string, ...[...[...string[]]]]; +declare type T15 = [boolean, number, ...string[]]; +declare type L15 = T15["length"]; +declare function assign(): void; +declare type T20 = [number, string, ...boolean[]]; +declare type T21 = T20[0]; +declare type T22 = T20[0 | 1]; +declare type T23 = T20[0 | 1 | 2]; +declare type T24 = T20[0 | 1 | 2 | 3]; +declare type T25 = T20[1 | 2 | 3]; +declare type T26 = T20[2 | 3]; +declare type T27 = T20[3]; +declare type T28 = T20[number]; +declare const t: T20; +declare const x: number; +declare let e0: number; +declare let e1: string; +declare let e2: boolean; +declare let e3: boolean; +declare let ex: string | number | boolean; +declare function f0(x: [T, ...U[]]): [T, U]; +declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; +declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; diff --git a/tests/baselines/reference/restTupleElements1.symbols b/tests/baselines/reference/restTupleElements1.symbols new file mode 100644 index 0000000000000..5880ffbc92c5e --- /dev/null +++ b/tests/baselines/reference/restTupleElements1.symbols @@ -0,0 +1,217 @@ +=== tests/cases/conformance/types/tuple/restTupleElements1.ts === +type T00 = [string?]; +>T00 : Symbol(T00, Decl(restTupleElements1.ts, 0, 0)) + +type T01 = [string, string?]; +>T01 : Symbol(T01, Decl(restTupleElements1.ts, 0, 21)) + +type T02 = [string?, string]; // Error +>T02 : Symbol(T02, Decl(restTupleElements1.ts, 1, 29)) + +type T03 = [...string[]]; +>T03 : Symbol(T03, Decl(restTupleElements1.ts, 2, 29)) + +type T04 = [...[...string[]]]; +>T04 : Symbol(T04, Decl(restTupleElements1.ts, 3, 25)) + +type T05 = [...[...[...string[]]]]; +>T05 : Symbol(T05, Decl(restTupleElements1.ts, 4, 30)) + +type T06 = [string, ...string[]]; +>T06 : Symbol(T06, Decl(restTupleElements1.ts, 5, 35)) + +type T07 = [...string[], string]; // Error +>T07 : Symbol(T07, Decl(restTupleElements1.ts, 6, 33)) + +type T08 = [...string]; // Error +>T08 : Symbol(T08, Decl(restTupleElements1.ts, 7, 33)) + +type T09 = [...string?]; // Error +>T09 : Symbol(T09, Decl(restTupleElements1.ts, 8, 23)) + +type T10 = [string, ...[...string[]]]; +>T10 : Symbol(T10, Decl(restTupleElements1.ts, 9, 24)) + +type T11 = [string, ...[...[...string[]]]]; +>T11 : Symbol(T11, Decl(restTupleElements1.ts, 10, 38)) + +type T15 = [boolean, number, ...string[]]; +>T15 : Symbol(T15, Decl(restTupleElements1.ts, 11, 43)) + +type L15 = T15["length"]; // number +>L15 : Symbol(L15, Decl(restTupleElements1.ts, 13, 42)) +>T15 : Symbol(T15, Decl(restTupleElements1.ts, 11, 43)) + +declare function assign(): void; +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) +>T : Symbol(T, Decl(restTupleElements1.ts, 16, 24)) +>S : Symbol(S, Decl(restTupleElements1.ts, 16, 26)) +>T : Symbol(T, Decl(restTupleElements1.ts, 16, 24)) + +assign(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[...number[]], number[]>(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], number[]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], []>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number]>(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number, number]>(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number, number, ...number[]]>(); +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number], [...number[]]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number], [number, ...number[]]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number, ...string[]]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [string, ...number[]]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number, number, string]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +assign<[number, ...number[]], [number, number, number, string]>(); // Error +>assign : Symbol(assign, Decl(restTupleElements1.ts, 14, 25)) + +type T20 = [number, string, ...boolean[]]; +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T21 = T20[0]; +>T21 : Symbol(T21, Decl(restTupleElements1.ts, 36, 42)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T22 = T20[0 | 1]; +>T22 : Symbol(T22, Decl(restTupleElements1.ts, 38, 18)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T23 = T20[0 | 1 | 2]; +>T23 : Symbol(T23, Decl(restTupleElements1.ts, 39, 22)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T24 = T20[0 | 1 | 2 | 3]; +>T24 : Symbol(T24, Decl(restTupleElements1.ts, 40, 26)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T25 = T20[1 | 2 | 3]; +>T25 : Symbol(T25, Decl(restTupleElements1.ts, 41, 30)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T26 = T20[2 | 3]; +>T26 : Symbol(T26, Decl(restTupleElements1.ts, 42, 26)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T27 = T20[3]; +>T27 : Symbol(T27, Decl(restTupleElements1.ts, 43, 22)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +type T28 = T20[number]; +>T28 : Symbol(T28, Decl(restTupleElements1.ts, 44, 18)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +declare const t: T20; +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) +>T20 : Symbol(T20, Decl(restTupleElements1.ts, 34, 66)) + +declare const x: number; +>x : Symbol(x, Decl(restTupleElements1.ts, 48, 13)) + +let e0 = t[0]; // number +>e0 : Symbol(e0, Decl(restTupleElements1.ts, 50, 3)) +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) +>0 : Symbol(0) + +let e1 = t[1]; // string +>e1 : Symbol(e1, Decl(restTupleElements1.ts, 51, 3)) +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) +>1 : Symbol(1) + +let e2 = t[2]; // boolean +>e2 : Symbol(e2, Decl(restTupleElements1.ts, 52, 3)) +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) + +let e3 = t[3]; // boolean +>e3 : Symbol(e3, Decl(restTupleElements1.ts, 53, 3)) +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) + +let ex = t[x]; // number | string | boolean +>ex : Symbol(ex, Decl(restTupleElements1.ts, 54, 3)) +>t : Symbol(t, Decl(restTupleElements1.ts, 47, 13)) +>x : Symbol(x, Decl(restTupleElements1.ts, 48, 13)) + +declare function f0(x: [T, ...U[]]): [T, U]; +>f0 : Symbol(f0, Decl(restTupleElements1.ts, 54, 14)) +>T : Symbol(T, Decl(restTupleElements1.ts, 56, 20)) +>U : Symbol(U, Decl(restTupleElements1.ts, 56, 22)) +>x : Symbol(x, Decl(restTupleElements1.ts, 56, 26)) +>T : Symbol(T, Decl(restTupleElements1.ts, 56, 20)) +>U : Symbol(U, Decl(restTupleElements1.ts, 56, 22)) +>T : Symbol(T, Decl(restTupleElements1.ts, 56, 20)) +>U : Symbol(U, Decl(restTupleElements1.ts, 56, 22)) + +f0([]); // Error +>f0 : Symbol(f0, Decl(restTupleElements1.ts, 54, 14)) + +f0([1]); +>f0 : Symbol(f0, Decl(restTupleElements1.ts, 54, 14)) + +f0([1, 2, 3]); +>f0 : Symbol(f0, Decl(restTupleElements1.ts, 54, 14)) + +f0([1, "hello", true]); +>f0 : Symbol(f0, Decl(restTupleElements1.ts, 54, 14)) + +declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; +>f1 : Symbol(f1, Decl(restTupleElements1.ts, 61, 23)) +>a : Symbol(a, Decl(restTupleElements1.ts, 63, 20)) +>x : Symbol(x, Decl(restTupleElements1.ts, 63, 25)) +>x : Symbol(x, Decl(restTupleElements1.ts, 63, 52)) + +declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; +>f2 : Symbol(f2, Decl(restTupleElements1.ts, 63, 84)) +>a : Symbol(a, Decl(restTupleElements1.ts, 64, 20)) +>x : Symbol(x, Decl(restTupleElements1.ts, 64, 28)) +>x : Symbol(x, Decl(restTupleElements1.ts, 64, 55)) + +f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]); +>f1 : Symbol(f1, Decl(restTupleElements1.ts, 61, 23)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 4)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 4)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 15)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 15)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 30)) +>x.charCodeAt : Symbol(String.charCodeAt, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 66, 30)) +>charCodeAt : Symbol(String.charCodeAt, Decl(lib.es5.d.ts, --, --)) + +f2(x => x * 2, x => x.length, x => x.charCodeAt(0)); +>f2 : Symbol(f2, Decl(restTupleElements1.ts, 63, 84)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 3)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 3)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 14)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 14)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 29)) +>x.charCodeAt : Symbol(String.charCodeAt, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(restTupleElements1.ts, 67, 29)) +>charCodeAt : Symbol(String.charCodeAt, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/restTupleElements1.types b/tests/baselines/reference/restTupleElements1.types new file mode 100644 index 0000000000000..bf749b1474086 --- /dev/null +++ b/tests/baselines/reference/restTupleElements1.types @@ -0,0 +1,270 @@ +=== tests/cases/conformance/types/tuple/restTupleElements1.ts === +type T00 = [string?]; +>T00 : [(string | undefined)?] + +type T01 = [string, string?]; +>T01 : [string, (string | undefined)?] + +type T02 = [string?, string]; // Error +>T02 : [string | undefined, string] + +type T03 = [...string[]]; +>T03 : string[] + +type T04 = [...[...string[]]]; +>T04 : string[] + +type T05 = [...[...[...string[]]]]; +>T05 : string[] + +type T06 = [string, ...string[]]; +>T06 : [string, ...string[]] + +type T07 = [...string[], string]; // Error +>T07 : [string[], string] + +type T08 = [...string]; // Error +>T08 : string[] + +type T09 = [...string?]; // Error +>T09 : (string | null)[] + +type T10 = [string, ...[...string[]]]; +>T10 : [string, ...string[]] + +type T11 = [string, ...[...[...string[]]]]; +>T11 : [string, ...string[]] + +type T15 = [boolean, number, ...string[]]; +>T15 : [boolean, number, ...string[]] + +type L15 = T15["length"]; // number +>L15 : number +>T15 : [boolean, number, ...string[]] + +declare function assign(): void; +>assign : () => void +>T : T +>S : S +>T : T + +assign(); +>assign() : void +>assign : () => void + +assign(); +>assign() : void +>assign : () => void + +assign<[...number[]], number[]>(); +>assign<[...number[]], number[]>() : void +>assign : () => void + +assign<[number, ...number[]], number[]>(); // Error +>assign<[number, ...number[]], number[]>() : any +>assign : () => void + +assign<[number, ...number[]], []>(); // Error +>assign<[number, ...number[]], []>() : any +>assign : () => void + +assign<[number, ...number[]], [number]>(); +>assign<[number, ...number[]], [number]>() : void +>assign : () => void + +assign<[number, ...number[]], [number, number]>(); +>assign<[number, ...number[]], [number, number]>() : void +>assign : () => void + +assign<[number, ...number[]], [number, number, ...number[]]>(); +>assign<[number, ...number[]], [number, number, ...number[]]>() : void +>assign : () => void + +assign<[number], [...number[]]>(); // Error +>assign<[number], [...number[]]>() : any +>assign : () => void + +assign<[number], [number, ...number[]]>(); // Error +>assign<[number], [number, ...number[]]>() : any +>assign : () => void + +assign<[number, ...number[]], [number, ...string[]]>(); // Error +>assign<[number, ...number[]], [number, ...string[]]>() : any +>assign : () => void + +assign<[number, ...number[]], [string, ...number[]]>(); // Error +>assign<[number, ...number[]], [string, ...number[]]>() : any +>assign : () => void + +assign<[number, ...number[]], [number, number, string]>(); // Error +>assign<[number, ...number[]], [number, number, string]>() : any +>assign : () => void + +assign<[number, ...number[]], [number, number, number, string]>(); // Error +>assign<[number, ...number[]], [number, number, number, string]>() : any +>assign : () => void + +type T20 = [number, string, ...boolean[]]; +>T20 : [number, string, ...boolean[]] + +type T21 = T20[0]; +>T21 : number +>T20 : [number, string, ...boolean[]] + +type T22 = T20[0 | 1]; +>T22 : string | number +>T20 : [number, string, ...boolean[]] + +type T23 = T20[0 | 1 | 2]; +>T23 : string | number | boolean +>T20 : [number, string, ...boolean[]] + +type T24 = T20[0 | 1 | 2 | 3]; +>T24 : string | number | boolean +>T20 : [number, string, ...boolean[]] + +type T25 = T20[1 | 2 | 3]; +>T25 : string | boolean +>T20 : [number, string, ...boolean[]] + +type T26 = T20[2 | 3]; +>T26 : boolean +>T20 : [number, string, ...boolean[]] + +type T27 = T20[3]; +>T27 : boolean +>T20 : [number, string, ...boolean[]] + +type T28 = T20[number]; +>T28 : string | number | boolean +>T20 : [number, string, ...boolean[]] + +declare const t: T20; +>t : [number, string, ...boolean[]] +>T20 : [number, string, ...boolean[]] + +declare const x: number; +>x : number + +let e0 = t[0]; // number +>e0 : number +>t[0] : number +>t : [number, string, ...boolean[]] +>0 : 0 + +let e1 = t[1]; // string +>e1 : string +>t[1] : string +>t : [number, string, ...boolean[]] +>1 : 1 + +let e2 = t[2]; // boolean +>e2 : boolean +>t[2] : boolean +>t : [number, string, ...boolean[]] +>2 : 2 + +let e3 = t[3]; // boolean +>e3 : boolean +>t[3] : boolean +>t : [number, string, ...boolean[]] +>3 : 3 + +let ex = t[x]; // number | string | boolean +>ex : string | number | boolean +>t[x] : string | number | boolean +>t : [number, string, ...boolean[]] +>x : number + +declare function f0(x: [T, ...U[]]): [T, U]; +>f0 : (x: [T, ...U[]]) => [T, U] +>T : T +>U : U +>x : [T, ...U[]] +>T : T +>U : U +>T : T +>U : U + +f0([]); // Error +>f0([]) : any +>f0 : (x: [T, ...U[]]) => [T, U] +>[] : never[] + +f0([1]); +>f0([1]) : [number, {}] +>f0 : (x: [T, ...U[]]) => [T, U] +>[1] : [number] +>1 : 1 + +f0([1, 2, 3]); +>f0([1, 2, 3]) : [number, number] +>f0 : (x: [T, ...U[]]) => [T, U] +>[1, 2, 3] : [number, number, number] +>1 : 1 +>2 : 2 +>3 : 3 + +f0([1, "hello", true]); +>f0([1, "hello", true]) : [number, string | boolean] +>f0 : (x: [T, ...U[]]) => [T, U] +>[1, "hello", true] : [number, string, true] +>1 : 1 +>"hello" : "hello" +>true : true + +declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; +>f1 : (a: [(x: number) => number, ...((x: string) => number)[]]) => void +>a : [(x: number) => number, ...((x: string) => number)[]] +>x : number +>x : string + +declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; +>f2 : (a_0: (x: number) => number, ...a_1: ((x: string) => number)[]) => void +>a : [(x: number) => number, ...((x: string) => number)[]] +>x : number +>x : string + +f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]); +>f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]) : void +>f1 : (a: [(x: number) => number, ...((x: string) => number)[]]) => void +>[x => x * 2, x => x.length, x => x.charCodeAt(0)] : [(x: number) => number, (x: string) => number, (x: string) => number] +>x => x * 2 : (x: number) => number +>x : number +>x * 2 : number +>x : number +>2 : 2 +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number +>x => x.charCodeAt(0) : (x: string) => number +>x : string +>x.charCodeAt(0) : number +>x.charCodeAt : (index: number) => number +>x : string +>charCodeAt : (index: number) => number +>0 : 0 + +f2(x => x * 2, x => x.length, x => x.charCodeAt(0)); +>f2(x => x * 2, x => x.length, x => x.charCodeAt(0)) : void +>f2 : (a_0: (x: number) => number, ...a_1: ((x: string) => number)[]) => void +>x => x * 2 : (x: number) => number +>x : number +>x * 2 : number +>x : number +>2 : 2 +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number +>x => x.charCodeAt(0) : (x: string) => number +>x : string +>x.charCodeAt(0) : number +>x.charCodeAt : (index: number) => number +>x : string +>charCodeAt : (index: number) => number +>0 : 0 + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types index 00ecd2659eead..618fc7c7805ab 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types @@ -429,7 +429,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] = ["trimmer", ["trimming", " for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robotA : [number, string, string] >i : number >0 : 0 @@ -448,7 +448,7 @@ for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { } for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -467,9 +467,9 @@ for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number } for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { ->numberA3 : string | number ->robotAInfo : (string | number)[] ->[2, "trimmer", "trimming"] : (string | number)[] +>numberA3 : number +>robotAInfo : string[] +>[2, "trimmer", "trimming"] : [number, string, string] >2 : 2 >"trimmer" : "trimmer" >"trimming" : "trimming" @@ -486,7 +486,7 @@ for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->numberA3 : string | number +>numberA3 : number } for (let [...multiRobotAInfo] = multiRobotA, i = 0; i < 1; i++) { >multiRobotAInfo : (string | [string, string])[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types index f317fa2a83cfd..802f21b64083d 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types @@ -531,7 +531,7 @@ for ([nameMA, [primarySkillA, secondarySkillA]] = ["trimmer", ["trimming", "edgi for ([numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = robotA, i = 0 : 0 >[numberA3, ...robotAInfo] = robotA : [number, string, string] ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -555,7 +555,7 @@ for ([numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { for ([numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = getRobot(), i = 0 : 0 >[numberA3, ...robotAInfo] = getRobot() : [number, string, string] ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -580,7 +580,7 @@ for ([numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { for ([numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0 : 0 >[numberA3, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types index 443f22bbab813..45a063c27d44d 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types @@ -534,7 +534,7 @@ for (let [numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robotA : [number, string, string] >i : number >0 : 0 @@ -555,7 +555,7 @@ for (let [numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -574,11 +574,11 @@ for (let [numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number } for (let [numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { ->numberA3 : string | number +>numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] ->[2, "trimmer", "trimming"] : (string | number)[] +>robotAInfo : string[] +>[2, "trimmer", "trimming"] : [number, string, string] >2 : 2 >"trimmer" : "trimmer" >"trimming" : "trimming" @@ -595,5 +595,5 @@ for (let [numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->numberA3 : string | number +>numberA3 : number } diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types index 0795142c6778d..01ddecf52f9d5 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types @@ -666,7 +666,7 @@ for ([nameMA = "noName", for ([numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = robotA, i = 0 : 0 >[numberA3 = -1, ...robotAInfo] = robotA : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 @@ -693,7 +693,7 @@ for ([numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { for ([numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = getRobot(), i = 0 : 0 >[numberA3 = -1, ...robotAInfo] = getRobot() : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 @@ -721,7 +721,7 @@ for ([numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { for ([numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0 : 0 >[numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types index 41dc32d2648c6..cf4f7c990bc5d 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types @@ -314,7 +314,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] of [multiRobotA, multiRobotB for (let [numberA3, ...robotAInfo] of robots) { >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robots : [number, string, string][] console.log(numberA3); @@ -326,7 +326,7 @@ for (let [numberA3, ...robotAInfo] of robots) { } for (let [numberA3, ...robotAInfo] of getRobots()) { >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -339,7 +339,7 @@ for (let [numberA3, ...robotAInfo] of getRobots()) { } for (let [numberA3, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types index abc08ee63d425..9c308a058ae0b 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types @@ -357,7 +357,7 @@ for ([nameMA, [primarySkillA, secondarySkillA]] of [multiRobotA, multiRobotB]) { } for ([numberA3, ...robotAInfo] of robots) { ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -371,7 +371,7 @@ for ([numberA3, ...robotAInfo] of robots) { >numberA3 : number } for ([numberA3, ...robotAInfo] of getRobots()) { ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -386,7 +386,7 @@ for ([numberA3, ...robotAInfo] of getRobots()) { >numberA3 : number } for ([numberA3, ...robotAInfo] of [robotA, robotB]) { ->[numberA3, ...robotAInfo] : (string | number)[] +>[numberA3, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 : number >...robotAInfo : string | number >robotAInfo : (string | number)[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types index e82c981033e7d..168147545113c 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types @@ -409,7 +409,7 @@ for (let [numberA3 = -1, ...robotAInfo] of robots) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robots : [number, string, string][] console.log(numberA3); @@ -423,7 +423,7 @@ for (let [numberA3 = -1, ...robotAInfo] of getRobots()) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -438,7 +438,7 @@ for (let [numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types index dad997dac4fe5..ed262d6a3d8e9 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types @@ -489,7 +489,7 @@ for ([nameMA = "noName", [ } for ([numberA3 = -1, ...robotAInfo] of robots) { ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 @@ -506,7 +506,7 @@ for ([numberA3 = -1, ...robotAInfo] of robots) { >numberA3 : number } for ([numberA3 = -1, ...robotAInfo] of getRobots()) { ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 @@ -524,7 +524,7 @@ for ([numberA3 = -1, ...robotAInfo] of getRobots()) { >numberA3 : number } for ([numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { ->[numberA3 = -1, ...robotAInfo] : (string | number)[] +>[numberA3 = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberA3 = -1 : -1 >numberA3 : number >-1 : -1 diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types index d7aed64a23282..eb9a5dce264d8 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types @@ -62,7 +62,7 @@ function foo3([numberA2, nameA2, skillA2]: Robot) { function foo4([numberA3, ...robotAInfo]: Robot) { >foo4 : ([numberA3, ...robotAInfo]: [number, string, string]) => void >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >Robot : [number, string, string] console.log(robotAInfo); @@ -70,7 +70,7 @@ function foo4([numberA3, ...robotAInfo]: Robot) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : (string | number)[] +>robotAInfo : string[] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types index a9d1013c136cf..ef4ee4f81bb37 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types @@ -86,7 +86,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >Robot : [number, string, string] >[-1, "name", "skill"] : [number, string, string] >-1 : -1 @@ -99,7 +99,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : (string | number)[] +>robotAInfo : string[] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types index 46bdfec4b06b2..f240f7fd40b3f 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types @@ -59,7 +59,7 @@ let [numberC, nameC, skillC] = [3, "edging", "Trimming edges"]; let [numberA3, ...robotAInfo] = robotA; >numberA3 : number ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types index bdd2059b863e8..3e5018a76c168 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types @@ -222,7 +222,7 @@ let multiRobotAInfo: (string | [string, string])[]; [numberB, ...robotAInfo] = robotB; >[numberB, ...robotAInfo] = robotB : [number, string, string] ->[numberB, ...robotAInfo] : (string | number)[] +>[numberB, ...robotAInfo] : [number, ...(string | number)[]] >numberB : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -230,7 +230,7 @@ let multiRobotAInfo: (string | [string, string])[]; [numberB, ...robotAInfo] = getRobotB(); >[numberB, ...robotAInfo] = getRobotB() : [number, string, string] ->[numberB, ...robotAInfo] : (string | number)[] +>[numberB, ...robotAInfo] : [number, ...(string | number)[]] >numberB : number >...robotAInfo : string | number >robotAInfo : (string | number)[] @@ -239,7 +239,7 @@ let multiRobotAInfo: (string | [string, string])[]; [numberB, ...robotAInfo] = [2, "trimmer", "trimming"]; >[numberB, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberB, ...robotAInfo] : (string | number)[] +>[numberB, ...robotAInfo] : [number, ...(string | number)[]] >numberB : number >...robotAInfo : string | number >robotAInfo : (string | number)[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types index fae55a6cabfef..4a166d0356995 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types @@ -73,7 +73,7 @@ let [numberA3 = -1, ...robotAInfo] = robotA; >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : (string | number)[] +>robotAInfo : string[] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types index 35c458f431066..e0c39abebc6b0 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types @@ -238,11 +238,11 @@ let multiRobotAInfo: (string | string[])[]; [nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = multiRobotB; >[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = multiRobotB : [string, string[]] ->[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string, string]] +>[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string?, string?]] >nameMB = "helloNoName" : "helloNoName" >nameMB : string >"helloNoName" : "helloNoName" ->[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string, string] +>[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string?, string?] >[primarySkillB = "noSkill", secondarySkillB = "noSkill"] : [string, string] >primarySkillB = "noSkill" : "noSkill" >primarySkillB : string @@ -250,16 +250,16 @@ let multiRobotAInfo: (string | string[])[]; >secondarySkillB = "noSkill" : "noSkill" >secondarySkillB : string >"noSkill" : "noSkill" ->[] : [string, string] +>[] : [string?, string?] >multiRobotB : [string, string[]] [nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = getMultiRobotB(); >[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = getMultiRobotB() : [string, string[]] ->[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string, string]] +>[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string?, string?]] >nameMB = "helloNoName" : "helloNoName" >nameMB : string >"helloNoName" : "helloNoName" ->[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string, string] +>[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string?, string?] >[primarySkillB = "noSkill", secondarySkillB = "noSkill"] : [string, string] >primarySkillB = "noSkill" : "noSkill" >primarySkillB : string @@ -267,17 +267,17 @@ let multiRobotAInfo: (string | string[])[]; >secondarySkillB = "noSkill" : "noSkill" >secondarySkillB : string >"noSkill" : "noSkill" ->[] : [string, string] +>[] : [string?, string?] >getMultiRobotB() : [string, string[]] >getMultiRobotB : () => [string, string[]] [nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = >[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] = ["trimmer", ["trimming", "edging"]] : [string, [string, string]] ->[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string, string]] +>[nameMB = "helloNoName", [primarySkillB = "noSkill", secondarySkillB = "noSkill"] = []] : [string, [string?, string?]] >nameMB = "helloNoName" : "helloNoName" >nameMB : string >"helloNoName" : "helloNoName" ->[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string, string] +>[primarySkillB = "noSkill", secondarySkillB = "noSkill"] = [] : [string?, string?] >[primarySkillB = "noSkill", secondarySkillB = "noSkill"] : [string, string] >primarySkillB = "noSkill" : "noSkill" >primarySkillB : string @@ -285,7 +285,7 @@ let multiRobotAInfo: (string | string[])[]; >secondarySkillB = "noSkill" : "noSkill" >secondarySkillB : string >"noSkill" : "noSkill" ->[] : [string, string] +>[] : [string?, string?] ["trimmer", ["trimming", "edging"]]; >["trimmer", ["trimming", "edging"]] : [string, [string, string]] @@ -296,7 +296,7 @@ let multiRobotAInfo: (string | string[])[]; [numberB = -1, ...robotAInfo] = robotB; >[numberB = -1, ...robotAInfo] = robotB : [number, string, string] ->[numberB = -1, ...robotAInfo] : (string | number)[] +>[numberB = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberB = -1 : -1 >numberB : number >-1 : -1 @@ -307,7 +307,7 @@ let multiRobotAInfo: (string | string[])[]; [numberB = -1, ...robotAInfo] = getRobotB(); >[numberB = -1, ...robotAInfo] = getRobotB() : [number, string, string] ->[numberB = -1, ...robotAInfo] : (string | number)[] +>[numberB = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberB = -1 : -1 >numberB : number >-1 : -1 @@ -319,7 +319,7 @@ let multiRobotAInfo: (string | string[])[]; [numberB = -1, ...robotAInfo] = [2, "trimmer", "trimming"]; >[numberB = -1, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberB = -1, ...robotAInfo] : (string | number)[] +>[numberB = -1, ...robotAInfo] : [number, ...(string | number)[]] >numberB = -1 : -1 >numberB : number >-1 : -1 diff --git a/tests/baselines/reference/strictFunctionTypes1.js b/tests/baselines/reference/strictFunctionTypes1.js index 94ee06f88f8fe..45d28f72501c5 100644 --- a/tests/baselines/reference/strictFunctionTypes1.js +++ b/tests/baselines/reference/strictFunctionTypes1.js @@ -50,11 +50,11 @@ declare function fo(x: Object): void; declare function fs(x: string): void; declare function fx(f: (x: "def") => void): void; declare const x1: (x: string) => void; -declare const x2 = "abc"; -declare const x3: string; +declare const x2: string; +declare const x3: Object; declare const x4: Func; declare const never: never; declare const x10: string; -declare const x11: "def"; +declare const x11: Object; declare function foo(a: ReadonlyArray): T; declare let x: never; diff --git a/tests/baselines/reference/strictFunctionTypes1.types b/tests/baselines/reference/strictFunctionTypes1.types index b915e0b5f6bcf..50b37f3e63b7f 100644 --- a/tests/baselines/reference/strictFunctionTypes1.types +++ b/tests/baselines/reference/strictFunctionTypes1.types @@ -78,16 +78,16 @@ const x1 = f1(fo, fs); // (x: string) => void >fs : (x: string) => void const x2 = f2("abc", fo, fs); // "abc" ->x2 : "abc" ->f2("abc", fo, fs) : "abc" +>x2 : string +>f2("abc", fo, fs) : string >f2 : (obj: T, f1: (x: T) => void, f2: (x: T) => void) => T >"abc" : "abc" >fo : (x: Object) => void >fs : (x: string) => void const x3 = f3("abc", fo, fx); // "abc" | "def" ->x3 : "def" | "abc" ->f3("abc", fo, fx) : "def" | "abc" +>x3 : Object +>f3("abc", fo, fx) : Object >f3 : (obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T >"abc" : "abc" >fo : (x: Object) => void @@ -112,8 +112,8 @@ const x10 = f2(never, fo, fs); // string >fs : (x: string) => void const x11 = f3(never, fo, fx); // "def" ->x11 : "def" ->f3(never, fo, fx) : "def" +>x11 : Object +>f3(never, fo, fx) : Object >f3 : (obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T >never : never >fo : (x: Object) => void diff --git a/tests/baselines/reference/strictTupleLength.errors.txt b/tests/baselines/reference/strictTupleLength.errors.txt index 23915f1f6fae6..a4a51cc9b0f4b 100644 --- a/tests/baselines/reference/strictTupleLength.errors.txt +++ b/tests/baselines/reference/strictTupleLength.errors.txt @@ -1,14 +1,11 @@ -tests/cases/conformance/types/tuple/strictTupleLength.ts(1,9): error TS1122: A tuple type element list cannot be empty. tests/cases/conformance/types/tuple/strictTupleLength.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't1' must be of type '[number]', but here has type '[number, number]'. tests/cases/conformance/types/tuple/strictTupleLength.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type '[number, number]', but here has type '[number]'. tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2322: Type 'number[]' is not assignable to type '[number]'. Property '0' is missing in type 'number[]'. -==== tests/cases/conformance/types/tuple/strictTupleLength.ts (4 errors) ==== +==== tests/cases/conformance/types/tuple/strictTupleLength.ts (3 errors) ==== var t0: []; - ~~ -!!! error TS1122: A tuple type element list cannot be empty. var t1: [number]; var t2: [number, number]; var arr: number[]; diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 16a8f66ba79a3..e2b73b7613acd 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,6 +1,5 @@ -tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'. - Property '0' is missing in type 'undefined[]'. +tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '[]' is not assignable to type '[number, string]'. + Property '0' is missing in type '[]'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]'. Property '1' is missing in type '[number]'. tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. @@ -8,7 +7,7 @@ tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' tests/cases/compiler/tupleTypes.ts(18,1): error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'. Types of property 'length' are incompatible. Type '3' is not assignable to type '2'. -tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'. +tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type '[]' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'. Types of property 'pop' are incompatible. Type '() => string | number' is not assignable to type '() => number'. @@ -25,10 +24,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n Type '{}' is not assignable to type 'string'. -==== tests/cases/compiler/tupleTypes.ts (10 errors) ==== +==== tests/cases/compiler/tupleTypes.ts (9 errors) ==== var v1: []; // Error - ~~ -!!! error TS1122: A tuple type element list cannot be empty. var v2: [number]; var v3: [number, string]; var v4: [number, [string, string]]; @@ -43,8 +40,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n t = []; // Error ~ -!!! error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'. -!!! error TS2322: Property '0' is missing in type 'undefined[]'. +!!! error TS2322: Type '[]' is not assignable to type '[number, string]'. +!!! error TS2322: Property '0' is missing in type '[]'. t = [1]; // Error ~ !!! error TS2322: Type '[number]' is not assignable to type '[number, string]'. @@ -83,7 +80,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n tt = [undefined, undefined]; tt = []; // Error ~~ -!!! error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'. +!!! error TS2322: Type '[]' is not assignable to type '[number, string]'. var a: number[]; var a1: [number, string]; diff --git a/tests/baselines/reference/tupleTypes.types b/tests/baselines/reference/tupleTypes.types index 3f68d4c7e2d53..2bedb1143127d 100644 --- a/tests/baselines/reference/tupleTypes.types +++ b/tests/baselines/reference/tupleTypes.types @@ -42,9 +42,9 @@ var t2: number|string; >t2 : string | number t = []; // Error ->t = [] : undefined[] +>t = [] : [] >t : [number, string] ->[] : undefined[] +>[] : [] t = [1]; // Error >t = [1] : [number] @@ -188,9 +188,9 @@ tt = [undefined, undefined]; >undefined : undefined tt = []; // Error ->tt = [] : undefined[] +>tt = [] : [] >tt : [number, string] ->[] : undefined[] +>[] : [] var a: number[]; >a : number[] diff --git a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts index 69b7462cd03b9..e45df9c45dfd1 100644 --- a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts +++ b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts @@ -59,7 +59,7 @@ function f7() { } function f8() { - var [a, b, c] = []; // Ok, [] is an array + var [a, b, c] = []; // Error, [] is an empty tuple var [d, e, f] = [1]; // Error, [1] is a tuple } @@ -149,31 +149,35 @@ function f19() { } function f20() { - var a: number[]; var x: number; var y: number; var z: number; + var a: number[]; + var a3: any[]; var [...a] = [1, 2, 3]; var [x, ...a] = [1, 2, 3]; var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a] = [1, 2, 3]; + var [x, y, z, ...a3] = [1, 2, 3]; [...a] = [1, 2, 3]; [x, ...a] = [1, 2, 3]; [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a] = [1, 2, 3]; + [x, y, z, ...a3] = [1, 2, 3]; } function f21() { - var a: (number | string | boolean)[]; - var x: number | string | boolean; - var y: number | string | boolean; - var z: number | string | boolean; - var [...a] = [1, "hello", true]; - var [x, ...a] = [1, "hello", true]; - var [x, y, ...a] = [1, "hello", true]; - var [x, y, z, ...a] = [1, "hello", true]; - [...a] = [1, "hello", true]; - [x, ...a] = [1, "hello", true]; - [x, y, ...a] = [1, "hello", true]; - [x, y, z, ...a] = [1, "hello", true]; + var x: number; + var y: string; + var z: boolean; + var a0: (number | string | boolean)[]; + var a1: (string | boolean)[]; + var a2: boolean[]; + var a3: any[]; + var [...a0] = [1, "hello", true]; + var [x, ...a1] = [1, "hello", true]; + var [x, y, ...a2] = [1, "hello", true]; + var [x, y, z, ...a3] = [1, "hello", true]; + [...a0] = [1, "hello", true]; + [x, ...a1] = [1, "hello", true]; + [x, y, ...a2] = [1, "hello", true]; + [x, y, z, ...a3] = [1, "hello", true]; } diff --git a/tests/cases/conformance/types/rest/genericRestParameters1.ts b/tests/cases/conformance/types/rest/genericRestParameters1.ts new file mode 100644 index 0000000000000..d3e65e754ece7 --- /dev/null +++ b/tests/cases/conformance/types/rest/genericRestParameters1.ts @@ -0,0 +1,157 @@ +// @strict: true +// @declaration: true + +declare let f1: (...x: [number, string, boolean]) => void; +declare let f2: (x0: number, x1: string, x2: boolean) => void; + +f1 = f2; +f2 = f1; + +declare const t3: [number, string, boolean]; +declare const t2: [string, boolean]; +declare const t1: [boolean]; +declare const t0: []; + +declare const ns: [number, string]; +declare const sn: [string, number]; + +f1(42, "hello", true); +f1(t3[0], t3[1], t3[2]); +f1(...t3); +f1(42, ...t2); +f1(42, "hello", ...t1); +f1(42, "hello", true, ...t0); +f1(ns[0], ns[1], true); +f1(...ns, true); // Error, tuple spread only expanded when last + +f2(42, "hello", true); +f2(t3[0], t3[1], t3[2]); +f2(...t3); +f2(42, ...t2); +f2(42, "hello", ...t1); +f2(42, "hello", true, ...t0); +f2(ns[0], ns[1], true); +f2(...ns, true); // Error, tuple spread only expanded when last + +declare function f10(...args: T): T; + +const x10 = f10(42, "hello", true); // [number, string, boolean] +const x11 = f10(42, "hello"); // [number, string] +const x12 = f10(42); // [number] +const x13 = f10(); // [] +const x14 = f10(...t3); // [number, string, boolean] +const x15 = f10(42, ...t2); // [number, string, boolean] +const x16 = f10(42, "hello", ...t1); // [number, string, boolean] +const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] +const x18 = f10(...ns, true); // (string | number | boolean)[] + +function g10(u: U, v: V) { + let x1 = f10(...u); // U + let x2 = f10(...v); // V + let x3 = f10(1, ...u); // [number, ...string[]] + let x4 = f10(...u, ...v); // (string | number)[] +} + +declare function f11(...args: T): T; + +const z10 = f11(42, "hello", true); // [42, "hello", true] +const z11 = f11(42, "hello"); // [42, "hello"] +const z12 = f11(42); // [42] +const z13 = f11(); // [] +const z14 = f11(...t3); // [number, string, boolean] +const z15 = f11(42, ...t2); // [42, string, boolean] +const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] +const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] +const z18 = f11(...ns, true); // (string | number | true)[] + +function g11(u: U, v: V) { + let x1 = f11(...u); // U + let x2 = f11(...v); // V + let x3 = f11(1, ...u); // [1, ...string[]] + let x4 = f11(...u, ...v); // (string | number)[] +} + +function call(f: (...args: T) => U, ...args: T) { + return f(...args); +} + +function callr(args: T, f: (...args: T) => U) { + return f(...args); +} + +declare function f15(a: string, b: number): string | number; +declare function f16(a: A, b: B): A | B; + +let x20 = call((x, y) => x + y, 10, 20); // number +let x21 = call((x, y) => x + y, 10, "hello"); // string +let x22 = call(f15, "hello", 42); // string | number +let x23 = call(f16, "hello", 42); // unknown +let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number + +let x30 = callr(sn, (x, y) => x + y); // string +let x31 = callr(sn, f15); // string | number +let x32 = callr(sn, f16); // string | number + +function bind(f: (x: T, ...rest: U) => V, x: T) { + return (...rest: U) => f(x, ...rest); +} + +declare const f20: (x: number, y: string, z: boolean) => string[]; + +const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] +const f22 = bind(f21, "hello"); // (z: boolean) => string[] +const f23 = bind(f22, true); // () => string[] + +f20(42, "hello", true); +f21("hello", true); +f22(true); +f23(); + +declare const g20: (x: number, y?: string, z?: boolean) => string[]; + +const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] +const g22 = bind(g21, "hello"); // (z: boolean) => string[] +const g23 = bind(g22, true); // () => string[] + +g20(42, "hello", true); +g20(42, "hello"); +g20(42); +g21("hello", true); +g21("hello"); +g21(); +g22(true); +g22(); +g23(); + +declare function f30 any)[]>(x: T, ...args: U): U; + +const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; + +type T01 = Parameters<(x: number, y: string, z: boolean) => void>; +type T02 = Parameters<(...args: [number, string, boolean]) => void>; +type T03 = Parameters void>; +type T04 = Parameters void>; +type T05 = Parameters<(...args: T[]) => void>; +type T06 = Parameters void>; +type T07 = Parameters<(...args: T) => void>; +type T08 = Parameters void>; +type T09 = Parameters; + +type Record1 = { + move: [number, 'left' | 'right']; + jump: [number, 'up' | 'down']; + stop: string; + done: []; +} + +type EventType = { + emit(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; +} + +declare var events: EventType; +events.emit('move', 10, 'left'); +events.emit('jump', 20, 'up'); +events.emit('stop', 'Bye!'); +events.emit('done'); diff --git a/tests/cases/conformance/types/rest/genericRestParameters2.ts b/tests/cases/conformance/types/rest/genericRestParameters2.ts new file mode 100644 index 0000000000000..1dc0d231dd2d6 --- /dev/null +++ b/tests/cases/conformance/types/rest/genericRestParameters2.ts @@ -0,0 +1,83 @@ +// @strict: true +// @declaration: true + +declare const t1: [number, string, ...boolean[]]; +declare const t2: [string, ...boolean[]]; +declare const t3: [...boolean[]]; +declare const t4: []; + +declare let f00: (...x: [number, string, boolean]) => void; +declare let f01: (a: number, ...x: [string, boolean]) => void; +declare let f02: (a: number, b: string, ...x: [boolean]) => void; +declare let f03: (a: number, b: string, c: boolean) => void; +declare let f04: (a: number, b: string, c: boolean, ...x: []) => void; + +declare let f10: (...x: [number, string, ...boolean[]]) => void; +declare let f11: (a: number, ...x: [string, ...boolean[]]) => void; +declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void; +declare let f13: (a: number, b: string, ...c: boolean[]) => void; + +declare const ns: [number, string]; +declare const sn: [string, number]; + +f10(42, "hello"); +f10(42, "hello", true); +f10(42, "hello", true, false); +f10(t1[0], t1[1], t1[2], t1[3]); +f10(...t1); +f10(42, ...t2); +f10(42, "hello", ...t3); +f10(42, "hello", true, ...t4); +f10(42, "hello", true, ...t4, false, ...t3); + +f11(42, "hello"); +f11(42, "hello", true); +f11(42, "hello", true, false); +f11(t1[0], t1[1], t1[2], t1[3]); +f11(...t1); +f11(42, ...t2); +f11(42, "hello", ...t3); +f11(42, "hello", true, ...t4); +f11(42, "hello", true, ...t4, false, ...t3); + +f12(42, "hello"); +f12(42, "hello", true); +f12(42, "hello", true, false); +f12(t1[0], t1[1], t1[2], t1[3]); +f12(...t1); +f12(42, ...t2); +f12(42, "hello", ...t3); +f12(42, "hello", true, ...t4); +f12(42, "hello", true, ...t4, false, ...t3); + +f13(42, "hello"); +f13(42, "hello", true); +f13(42, "hello", true, false); +f13(t1[0], t1[1], t1[2], t1[3]); +f13(...t1); +f13(42, ...t2); +f13(42, "hello", ...t3); +f13(42, "hello", true, ...t4); +f13(42, "hello", true, ...t4, false, ...t3); + +declare const f20: (...args: T) => T; + +f20(...t1); +f20(42, ...t2); +f20(42, "hello", ...t3); +f20(42, "hello", ...t2, true); + +type Parameters = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; + +type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>; +type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>; +type T03 = Parameters void>; +type T04 = Parameters void>; +type T05 = Parameters<(x: string, ...args: T) => void>; +type T06 = T05<[number, ...boolean[]]>; + +type P1 = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[]; + +type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>; +type T11 = P1<(...z: number[]) => void>; +type T12 = P1<(x: number, y: number) => void>; diff --git a/tests/cases/conformance/types/tuple/optionalTupleElements1.ts b/tests/cases/conformance/types/tuple/optionalTupleElements1.ts new file mode 100644 index 0000000000000..a2a343af737c2 --- /dev/null +++ b/tests/cases/conformance/types/tuple/optionalTupleElements1.ts @@ -0,0 +1,47 @@ +// @strict: true +// @declaration: true + +type T1 = [number, string, boolean]; +type T2 = [number, string, boolean?]; +type T3 = [number, string?, boolean?]; +type T4 = [number?, string?, boolean?]; + +type L1 = T1["length"]; +type L2 = T2["length"]; +type L3 = T3["length"]; +type L4 = T4["length"]; + +type T5 = [number, string?, boolean]; // Error + +function f1(t1: T1, t2: T2, t3: T3, t4: T4) { + t1 = t1; + t1 = t2; // Error + t1 = t3; // Error + t1 = t4; // Error + t2 = t1; + t2 = t2; + t2 = t3; // Error + t2 = t4; // Error + t3 = t1; + t3 = t2; + t3 = t3; + t3 = t4; // Error + t4 = t1; + t4 = t2; + t4 = t3; + t4 = t4; +} + +let t2: T2; +let t3: T3; +let t4: T4; + +t2 = [42, "hello"]; +t3 = [42, "hello"]; +t3 = [42,,true] +t3 = [42]; +t4 = [42, "hello"]; +t4 = [42,,true]; +t4 = [,"hello", true]; +t4 = [,,true]; +t4 = []; diff --git a/tests/cases/conformance/types/tuple/restTupleElements1.ts b/tests/cases/conformance/types/tuple/restTupleElements1.ts new file mode 100644 index 0000000000000..040ce66003a96 --- /dev/null +++ b/tests/cases/conformance/types/tuple/restTupleElements1.ts @@ -0,0 +1,71 @@ +// @strict: true +// @declaration: true + +type T00 = [string?]; +type T01 = [string, string?]; +type T02 = [string?, string]; // Error +type T03 = [...string[]]; +type T04 = [...[...string[]]]; +type T05 = [...[...[...string[]]]]; +type T06 = [string, ...string[]]; +type T07 = [...string[], string]; // Error +type T08 = [...string]; // Error +type T09 = [...string?]; // Error +type T10 = [string, ...[...string[]]]; +type T11 = [string, ...[...[...string[]]]]; + +type T15 = [boolean, number, ...string[]]; +type L15 = T15["length"]; // number + +declare function assign(): void; + +assign(); +assign(); +assign<[...number[]], number[]>(); + +assign<[number, ...number[]], number[]>(); // Error +assign<[number, ...number[]], []>(); // Error +assign<[number, ...number[]], [number]>(); +assign<[number, ...number[]], [number, number]>(); +assign<[number, ...number[]], [number, number, ...number[]]>(); + +assign<[number], [...number[]]>(); // Error +assign<[number], [number, ...number[]]>(); // Error + +assign<[number, ...number[]], [number, ...string[]]>(); // Error +assign<[number, ...number[]], [string, ...number[]]>(); // Error +assign<[number, ...number[]], [number, number, string]>(); // Error +assign<[number, ...number[]], [number, number, number, string]>(); // Error + +type T20 = [number, string, ...boolean[]]; + +type T21 = T20[0]; +type T22 = T20[0 | 1]; +type T23 = T20[0 | 1 | 2]; +type T24 = T20[0 | 1 | 2 | 3]; +type T25 = T20[1 | 2 | 3]; +type T26 = T20[2 | 3]; +type T27 = T20[3]; +type T28 = T20[number]; + +declare const t: T20; +declare const x: number; + +let e0 = t[0]; // number +let e1 = t[1]; // string +let e2 = t[2]; // boolean +let e3 = t[3]; // boolean +let ex = t[x]; // number | string | boolean + +declare function f0(x: [T, ...U[]]): [T, U]; + +f0([]); // Error +f0([1]); +f0([1, 2, 3]); +f0([1, "hello", true]); + +declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void; +declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void; + +f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]); +f2(x => x * 2, x => x.length, x => x.charCodeAt(0));