diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index d392785d4181f..8ba71303c2940 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -2583,6 +2583,8 @@ func (c *Checker) checkDeferredNode(node *ast.Node) { c.checkFunctionExpressionOrObjectLiteralMethodDeferred(node) case ast.KindGetAccessor, ast.KindSetAccessor: c.checkAccessorDeclaration(node) + case ast.KindClassDeclaration: + c.checkClassLikeDeclarationDeferred(node) case ast.KindClassExpression: c.checkClassExpressionDeferred(node) case ast.KindTypeParameter: @@ -3043,7 +3045,7 @@ func (c *Checker) checkAccessorDeclaration(node *ast.Node) { } } } - returnType := c.getTypeOfAccessors(c.getSymbolOfDeclaration(node)) + returnType := c.getTypeOfSymbol(c.getSymbolOfDeclaration(node)) if node.Kind == ast.KindGetAccessor { c.checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnType) } @@ -4339,6 +4341,7 @@ func (c *Checker) checkClassDeclaration(node *ast.Node) { c.grammarErrorOnFirstToken(node, diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name) } c.checkClassLikeDeclaration(node) + c.checkNodeDeferred(node) c.checkSourceElements(node.Members()) c.checkConstructorDeclaredProperties(node) c.registerForUnusedIdentifiersCheck(node) @@ -4387,7 +4390,6 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) { c.checkJSDocAugmentsTagMatchesExtends(node, baseTypeNode, baseType) staticBaseType := c.getApparentType(baseConstructorType) c.checkBaseTypeAccessibility(staticBaseType, baseTypeNode) - c.checkSourceElement(baseTypeNode.Expression()) if len(baseTypeNode.TypeArguments()) != 0 { c.checkSourceElements(baseTypeNode.TypeArguments()) for _, constructor := range c.getConstructorsForTypeArguments(staticBaseType, baseTypeNode.TypeArguments(), baseTypeNode) { @@ -4459,6 +4461,12 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) { c.checkPropertyInitialization(node) } +func (c *Checker) checkClassLikeDeclarationDeferred(node *ast.Node) { + if baseTypeNode := ast.GetClassExtendsHeritageElement(node); baseTypeNode != nil { + c.checkExpression(baseTypeNode.Expression()) + } +} + func (c *Checker) checkClassForStaticPropertyNameConflicts(node *ast.Node) { if c.compilerOptions.GetUseDefineForClassFields() { return @@ -5234,7 +5242,10 @@ func (c *Checker) checkEnumMember(node *ast.Node) { c.checkExpression(node.Name().Expression()) } if node.Initializer() != nil { - c.checkExpression(node.Initializer()) + initializerType := c.checkExpression(node.Initializer()) + if c.getEnumMemberValue(node).Value == nil && !ast.IsEnumConst(node.Parent) && node.Parent.Flags&ast.NodeFlagsAmbient == 0 { + c.checkTypeAssignableTo(initializerType, c.numberType, node.Initializer(), diagnostics.Type_0_is_not_assignable_to_type_1_as_required_for_computed_enum_member_values) + } } } @@ -6083,7 +6094,7 @@ func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error if initializer != nil && !ast.IsForInStatement(node.Parent.Parent) { - initializerType := c.checkExpressionCached(initializer) + initializerType := c.checkExpression(initializer) c.checkTypeAssignableToAndOptionallyElaborate(initializerType, t, node, initializer, nil /*headMessage*/, nil) blockScopeKind := c.getCombinedNodeFlagsCached(node) & ast.NodeFlagsBlockScoped if blockScopeKind == ast.NodeFlagsAwaitUsing { @@ -10267,7 +10278,6 @@ func (c *Checker) checkParenthesizedExpression(node *ast.Node, checkMode CheckMo } func (c *Checker) checkClassExpression(node *ast.Node) *Type { - c.checkClassLikeDeclaration(node) c.checkNodeDeferred(node) c.checkClassExpressionExternalHelpers(node) return c.getTypeOfSymbol(c.getSymbolOfDeclaration(node)) @@ -10329,6 +10339,8 @@ func (c *Checker) checkClassExpressionExternalHelpers(node *ast.ClassExpressionN } func (c *Checker) checkClassExpressionDeferred(node *ast.Node) { + c.checkClassLikeDeclaration(node) + c.checkClassLikeDeclarationDeferred(node) c.checkSourceElements(node.Members()) c.checkConstructorDeclaredProperties(node) c.registerForUnusedIdentifiersCheck(node) @@ -16807,16 +16819,11 @@ func (c *Checker) getDeclarationOfAliasSymbol(symbol *ast.Symbol) *ast.Node { } func (c *Checker) getTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - deferred := c.deferredSymbolLinks.Get(symbol) - if deferred.parent.flags&TypeFlagsUnion != 0 { - links.resolvedType = c.getUnionType(deferred.constituents) - } else { - links.resolvedType = c.getIntersectionType(deferred.constituents) - } + deferred := c.deferredSymbolLinks.Get(symbol) + if deferred.parent.flags&TypeFlagsUnion != 0 { + return c.getUnionType(deferred.constituents) } - return links.resolvedType + return c.getIntersectionType(deferred.constituents) } func (c *Checker) getWriteTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type { @@ -16830,7 +16837,7 @@ func (c *Checker) getWriteTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type links.setWriteType(c, c.getIntersectionType(deferred.writeConstituents)) } } else { - links.setWriteType(c, c.getTypeOfSymbolWithDeferredType(symbol)) + links.setWriteType(c, c.getTypeOfSymbol(symbol)) } } return links.getWriteType() @@ -16899,6 +16906,41 @@ func (c *Checker) GetTypeOfSymbolAtLocation(symbol *ast.Symbol, location *ast.No } func (c *Checker) getTypeOfSymbol(symbol *ast.Symbol) *Type { + return c.getTypeWithBaseTypeVariable(c.getTypeOfSymbolWithCache(symbol)) +} + +func (c *Checker) getTypeOfSymbolWithCache(symbol *ast.Symbol) *Type { + links := c.valueSymbolLinks.Get(symbol) + if links.resolvedType != nil { + return links.resolvedType + } + if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { + if symbol.CheckFlags()&(ast.CheckFlagsDeferredType|ast.CheckFlagsInstantiated) == 0 && symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { + links.getContainingType().AsMappedType().containsError = true + } + return c.errorType + } + result := c.getTypeOfSymbolWorker(symbol) + if result == nil { + panic("Unexpected nil type") + } + if !c.popTypeResolution() { + links.resolvedType = c.errorType + c.reportSymbolTypeCircularity(symbol) + return links.resolvedType + } + // For a contextually typed parameter it is possible that a type has already + // been assigned (in assignTypeToParameterAndFixTypeParameters), and we want + // to preserve this type. In fact, we need to _prefer_ that type, but it won't + // be assigned until contextual typing is complete, so we need to defer in + // cases where contextual typing may take place. + if links.resolvedType == nil && !c.isParameterOfContextSensitiveSignature(symbol) { + links.resolvedType = result + } + return core.OrElse(links.resolvedType, result) +} + +func (c *Checker) getTypeOfSymbolWorker(symbol *ast.Symbol) *Type { if symbol.CheckFlags()&ast.CheckFlagsDeferredType != 0 { return c.getTypeOfSymbolWithDeferredType(symbol) } @@ -16929,16 +16971,49 @@ func (c *Checker) getTypeOfSymbol(symbol *ast.Symbol) *Type { return c.errorType } +func (c *Checker) reportSymbolTypeCircularity(symbol *ast.Symbol) { + if symbol.CheckFlags()&(ast.CheckFlagsDeferredType|ast.CheckFlagsInstantiated) != 0 { + c.reportCircularityError(symbol) + return + } + if symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { + c.error(c.currentNode, diagnostics.Type_of_property_0_circularly_references_itself_in_mapped_type_1, c.symbolToString(symbol), c.TypeToString(c.valueSymbolLinks.Get(symbol).getContainingType())) + return + } + if symbol.CheckFlags()&ast.CheckFlagsReverseMapped != 0 { + c.reportCircularityError(symbol) + return + } + if symbol.Flags()&ast.SymbolFlagsAccessor != 0 { + getter := ast.GetDeclarationOfKind(symbol, ast.KindGetAccessor) + setter := ast.GetDeclarationOfKind(symbol, ast.KindSetAccessor) + accessor := core.Find(symbol.Declarations(), ast.IsAutoAccessorPropertyDeclaration) + if c.getAnnotatedAccessorTypeNode(getter) != nil { + c.error(getter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) + } else if c.getAnnotatedAccessorTypeNode(setter) != nil { + c.error(setter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) + } else if c.getAnnotatedAccessorTypeNode(accessor) != nil { + c.error(setter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) + } else if getter != nil && c.noImplicitAny { + c.error(getter, diagnostics.X_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, c.symbolToString(symbol)) + } + return + } + if symbol.Flags()&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty|ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule|ast.SymbolFlagsEnumMember) == 0 && symbol.Flags()&ast.SymbolFlagsAlias != 0 { + exportSymbol := c.getTargetOfAliasDeclaration(c.getDeclarationOfAliasSymbol(symbol)) + c.reportCircularityError(core.OrElse(exportSymbol, symbol)) + return + } + c.reportCircularityError(symbol) +} + func (c *Checker) getNonMissingTypeOfSymbol(symbol *ast.Symbol) *Type { return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags()&ast.SymbolFlagsOptional != 0) } func (c *Checker) getTypeOfInstantiatedSymbol(symbol *ast.Symbol) *Type { links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - links.resolvedType = c.instantiateType(c.getTypeOfSymbol(links.target), links.mapper) - } - return links.resolvedType + return c.instantiateType(c.getTypeOfSymbol(links.target), links.mapper) } func (c *Checker) getWriteTypeOfInstantiatedSymbol(symbol *ast.Symbol) *Type { @@ -16949,26 +17024,6 @@ func (c *Checker) getWriteTypeOfInstantiatedSymbol(symbol *ast.Symbol) *Type { return links.getWriteType() } -func (c *Checker) getTypeOfVariableOrParameterOrProperty(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - t := c.getTypeOfVariableOrParameterOrPropertyWorker(symbol) - if t == nil { - panic("Unexpected nil type") - } - // For a contextually typed parameter it is possible that a type has already - // been assigned (in assignTypeToParameterAndFixTypeParameters), and we want - // to preserve this type. In fact, we need to _prefer_ that type, but it won't - // be assigned until contextual typing is complete, so we need to defer in - // cases where contextual typing may take place. - if links.resolvedType == nil && !c.isParameterOfContextSensitiveSignature(symbol) { - links.resolvedType = t - } - return t - } - return links.resolvedType -} - func (c *Checker) isParameterOfContextSensitiveSignature(symbol *ast.Symbol) bool { decl := symbol.ValueDeclaration() if decl == nil { @@ -16983,7 +17038,7 @@ func (c *Checker) isParameterOfContextSensitiveSignature(symbol *ast.Symbol) boo return false } -func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbol) *Type { +func (c *Checker) getTypeOfVariableOrParameterOrProperty(symbol *ast.Symbol) *Type { // Handle prototype property if symbol.Flags()&ast.SymbolFlagsPrototype != 0 { return c.getTypeOfPrototypeProperty(symbol) @@ -17002,9 +17057,6 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo return c.getWidenedType(c.getWidenedLiteralType(c.checkExpression(statements[0].Expression()))) } // Handle variable, parameter or property - if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { - return c.reportCircularityError(symbol) - } if symbol.Flags()&ast.SymbolFlagsModuleExports != 0 { if symbol.Name() == "exports" { return c.getTypeOfSymbol(c.resolveExternalModuleSymbol(symbol.ValueDeclaration().Symbol(), false /*dontResolveAlias*/)) @@ -17037,9 +17089,6 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo default: panic("Unhandled case in getTypeOfVariableOrParameterOrPropertyWorker: " + declaration.Kind.String()) } - if !c.popTypeResolution() { - return c.reportCircularityError(symbol) - } return result } @@ -17311,14 +17360,6 @@ func (c *Checker) getWidenedLiteralTypeForInitializer(declaration *ast.Node, t * } func (c *Checker) getTypeOfFuncClassEnumModule(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - links.resolvedType = c.getTypeOfFuncClassEnumModuleWorker(symbol) - } - return links.resolvedType -} - -func (c *Checker) getTypeOfFuncClassEnumModuleWorker(symbol *ast.Symbol) *Type { if symbol.Flags()&ast.SymbolFlagsModule != 0 && isShorthandAmbientModuleSymbol(symbol) { return c.anyType } else if symbol.Flags()&ast.SymbolFlagsValueModule != 0 && symbol.ValueDeclaration() != nil && @@ -17330,10 +17371,6 @@ func (c *Checker) getTypeOfFuncClassEnumModuleWorker(symbol *ast.Symbol) *Type { } t := c.newObjectType(ObjectFlagsAnonymous, symbol) if symbol.Flags()&ast.SymbolFlagsClass != 0 { - baseTypeVariable := c.getBaseTypeVariableOfClass(symbol) - if baseTypeVariable != nil { - return c.getIntersectionType([]*Type{t, baseTypeVariable}) - } return t } if c.strictNullChecks && symbol.Flags()&ast.SymbolFlagsOptional != 0 { @@ -17342,6 +17379,19 @@ func (c *Checker) getTypeOfFuncClassEnumModuleWorker(symbol *ast.Symbol) *Type { return t } +func (c *Checker) getTypeWithBaseTypeVariable(t *Type) *Type { + if t.flags&TypeFlagsObject != 0 && t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsClass != 0 { + baseTypeVariable := c.getBaseTypeVariableOfClass(t.symbol) + if baseTypeVariable != nil { + if mapper := t.AsObjectType().mapper; mapper != nil { + baseTypeVariable = c.instantiateType(baseTypeVariable, mapper) + } + return c.getIntersectionType([]*Type{t, baseTypeVariable}) + } + } + return t +} + func (c *Checker) getBaseTypeVariableOfClass(symbol *ast.Symbol) *Type { baseConstructorType := c.getBaseConstructorTypeOfClass(c.getDeclaredTypeOfClassOrInterface(symbol)) switch { @@ -17376,7 +17426,7 @@ func (c *Checker) getBaseConstructorTypeOfClass(t *Type) *Type { if !c.pushTypeResolution(t, TypeSystemPropertyNameResolvedBaseConstructorType) { return c.errorType } - baseConstructorType := c.checkExpression(baseTypeNode.Expression()) + baseConstructorType := c.getTypeOfExpression(baseTypeNode.Expression()) if baseConstructorType.flags&(TypeFlagsObject|TypeFlagsIntersection) != 0 { // Resolving the members of a class requires us to resolve the base class of that class. // We force resolution here such that we catch circularities now. @@ -18937,66 +18987,41 @@ func (c *Checker) getUndefinedProperty(prop *ast.Symbol) *ast.Symbol { } func (c *Checker) getTypeOfEnumMember(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - links.resolvedType = c.getDeclaredTypeOfEnumMember(symbol) - } - return links.resolvedType + return c.getDeclaredTypeOfEnumMember(symbol) } func (c *Checker) getTypeOfAccessors(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { - return c.errorType - } - getter := ast.GetDeclarationOfKind(symbol, ast.KindGetAccessor) - setter := ast.GetDeclarationOfKind(symbol, ast.KindSetAccessor) - accessor := core.Find(symbol.Declarations(), ast.IsAutoAccessorPropertyDeclaration) - // We try to resolve a getter type annotation, a setter type annotation, or a getter function - // body return type inference, in that order. - t := c.getAnnotatedAccessorType(getter) - if t == nil { - t = c.getAnnotatedAccessorType(setter) - } - if t == nil { - t = c.getAnnotatedAccessorType(accessor) - } - if t == nil && getter != nil { - if body := getter.Body(); body != nil { - t = c.getReturnTypeFromBody(getter, CheckModeNormal) - } - } - if t == nil && accessor != nil { - t = c.getWidenedTypeForVariableLikeDeclaration(accessor, true /*reportErrors*/) - } - if t == nil { - if setter != nil && !isPrivateWithinAmbient(setter) { - c.errorOrSuggestion(c.noImplicitAny, setter, diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, c.symbolToString(symbol)) - } else if getter != nil && !isPrivateWithinAmbient(getter) { - c.errorOrSuggestion(c.noImplicitAny, getter, diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, c.symbolToString(symbol)) - } else if accessor != nil && !isPrivateWithinAmbient(accessor) { - c.errorOrSuggestion(c.noImplicitAny, accessor, diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), "any") - } - t = c.anyType - } - if !c.popTypeResolution() { - if c.getAnnotatedAccessorTypeNode(getter) != nil { - c.error(getter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) - } else if c.getAnnotatedAccessorTypeNode(setter) != nil { - c.error(setter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) - } else if c.getAnnotatedAccessorTypeNode(accessor) != nil { - c.error(setter, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) - } else if getter != nil && c.noImplicitAny { - c.error(getter, diagnostics.X_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, c.symbolToString(symbol)) - } - t = c.anyType + getter := ast.GetDeclarationOfKind(symbol, ast.KindGetAccessor) + setter := ast.GetDeclarationOfKind(symbol, ast.KindSetAccessor) + accessor := core.Find(symbol.Declarations(), ast.IsAutoAccessorPropertyDeclaration) + // We try to resolve a getter type annotation, a setter type annotation, or a getter function + // body return type inference, in that order. + t := c.getAnnotatedAccessorType(getter) + if t == nil { + t = c.getAnnotatedAccessorType(setter) + } + if t == nil { + t = c.getAnnotatedAccessorType(accessor) + } + if t == nil && getter != nil { + if body := getter.Body(); body != nil { + t = c.getReturnTypeFromBody(getter, CheckModeNormal) } - if links.resolvedType == nil { - links.resolvedType = t + } + if t == nil && accessor != nil { + t = c.getWidenedTypeForVariableLikeDeclaration(accessor, true /*reportErrors*/) + } + if t == nil { + if setter != nil && !isPrivateWithinAmbient(setter) { + c.errorOrSuggestion(c.noImplicitAny, setter, diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, c.symbolToString(symbol)) + } else if getter != nil && !isPrivateWithinAmbient(getter) { + c.errorOrSuggestion(c.noImplicitAny, getter, diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, c.symbolToString(symbol)) + } else if accessor != nil && !isPrivateWithinAmbient(accessor) { + c.errorOrSuggestion(c.noImplicitAny, accessor, diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), "any") } + t = c.anyType } - return links.resolvedType + return t } func (c *Checker) getWriteTypeOfAccessors(symbol *ast.Symbol) *Type { @@ -19024,7 +19049,7 @@ func (c *Checker) getWriteTypeOfAccessors(symbol *ast.Symbol) *Type { if writeType != nil { links.setWriteType(c, writeType) } else { - links.setWriteType(c, c.getTypeOfAccessors(symbol)) + links.setWriteType(c, c.getTypeOfSymbol(symbol)) } } } @@ -19032,34 +19057,16 @@ func (c *Checker) getWriteTypeOfAccessors(symbol *ast.Symbol) *Type { } func (c *Checker) getTypeOfAlias(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { - return c.errorType - } - targetSymbol := c.resolveAlias(symbol) - exportSymbol := c.getTargetOfAliasDeclaration(c.getDeclarationOfAliasSymbol(symbol)) - // It only makes sense to get the type of a value symbol. If the result of resolving - // the alias is not a value, then it has no type. To get the type associated with a - // type symbol, call getDeclaredTypeOfSymbol. - // This check is important because without it, a call to getTypeOfSymbol could end - // up recursively calling getTypeOfAlias, causing a stack overflow. - if links.resolvedType == nil { - if c.getSymbolFlags(targetSymbol)&ast.SymbolFlagsValue != 0 { - links.resolvedType = c.getTypeOfSymbol(targetSymbol) - } else { - links.resolvedType = c.errorType - } - } - if !c.popTypeResolution() { - c.reportCircularityError(core.OrElse(exportSymbol, symbol)) - if links.resolvedType == nil { - links.resolvedType = c.errorType - } - return links.resolvedType - } + targetSymbol := c.resolveAlias(symbol) + // It only makes sense to get the type of a value symbol. If the result of resolving + // the alias is not a value, then it has no type. To get the type associated with a + // type symbol, call getDeclaredTypeOfSymbol. + // This check is important because without it, a call to getTypeOfSymbol could end + // up recursively calling getTypeOfAlias, causing a stack overflow. + if c.getSymbolFlags(targetSymbol)&ast.SymbolFlagsValue != 0 { + return c.getTypeOfSymbol(targetSymbol) } - return links.resolvedType + return c.errorType } func (c *Checker) addOptionality(t *Type) *Type { @@ -19265,7 +19272,11 @@ func (c *Checker) reportCircularityError(symbol *ast.Symbol) *Type { } // Check if variable has initializer that circularly references the variable itself if c.noImplicitAny && (!ast.IsParameterDeclaration(declaration) || declaration.Initializer() != nil) { - c.error(symbol.ValueDeclaration(), diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, c.symbolToString(symbol)) + message := diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer + if ast.IsGetAccessorDeclaration(declaration) { + message = diagnostics.X_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions + } + c.error(declaration, message, c.symbolToString(symbol)) } } else if symbol.Flags()&ast.SymbolFlagsAlias != 0 { node := c.getDeclarationOfAliasSymbol(symbol) @@ -21424,36 +21435,20 @@ func (c *Checker) resolveMappedTypeMembers(t *Type) { func (c *Checker) getTypeOfMappedSymbol(symbol *ast.Symbol) *Type { links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - mappedType := links.getContainingType() - if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { - mappedType.AsMappedType().containsError = true - return c.errorType - } - templateType := c.getTemplateTypeFromMappedType(core.OrElse(mappedType.AsMappedType().target, mappedType)) - mapper := appendTypeMapping(mappedType.AsMappedType().mapper, c.getTypeParameterFromMappedType(mappedType), c.mappedSymbolLinks.Get(symbol).keyType) - propType := c.instantiateType(templateType, mapper) - // When creating an optional property in strictNullChecks mode, if 'undefined' isn't assignable to the - // type, we include 'undefined' in the type. Similarly, when creating a non-optional property in strictNullChecks - // mode, if the underlying property is optional we remove 'undefined' from the type. - switch { - case c.strictNullChecks && symbol.Flags()&ast.SymbolFlagsOptional != 0 && !c.maybeTypeOfKind(propType, TypeFlagsUndefined|TypeFlagsVoid): - propType = c.getOptionalType(propType, true /*isProperty*/) - case symbol.CheckFlags()&ast.CheckFlagsStripOptional != 0: - propType = c.removeMissingOrUndefinedType(propType) - } - if c.popTypeResolution() { - if links.resolvedType == nil { - links.resolvedType = propType - } - } else { - if links.resolvedType == nil { - links.resolvedType = c.errorType - } - c.error(c.currentNode, diagnostics.Type_of_property_0_circularly_references_itself_in_mapped_type_1, c.symbolToString(symbol), c.TypeToString(mappedType)) - } + mappedType := links.getContainingType() + templateType := c.getTemplateTypeFromMappedType(core.OrElse(mappedType.AsMappedType().target, mappedType)) + mapper := appendTypeMapping(mappedType.AsMappedType().mapper, c.getTypeParameterFromMappedType(mappedType), c.mappedSymbolLinks.Get(symbol).keyType) + propType := c.instantiateType(templateType, mapper) + // When creating an optional property in strictNullChecks mode, if 'undefined' isn't assignable to the + // type, we include 'undefined' in the type. Similarly, when creating a non-optional property in strictNullChecks + // mode, if the underlying property is optional we remove 'undefined' from the type. + switch { + case c.strictNullChecks && symbol.Flags()&ast.SymbolFlagsOptional != 0 && !c.maybeTypeOfKind(propType, TypeFlagsUndefined|TypeFlagsVoid): + propType = c.getOptionalType(propType, true /*isProperty*/) + case symbol.CheckFlags()&ast.CheckFlagsStripOptional != 0: + propType = c.removeMissingOrUndefinedType(propType) } - return links.resolvedType + return propType } // Return the lower bound of the key type in a mapped type. Intuitively, the lower @@ -24508,6 +24503,7 @@ func (c *Checker) getDeclaredTypeOfEnumMember(symbol *ast.Symbol) *Type { } func (c *Checker) computeEnumMemberValues(node *ast.Node) { + // Initializer type-checking belongs in checkEnumMember: doing it here can cache enum types from incomplete values. nodeLinks := c.nodeLinks.Get(node) if !(nodeLinks.flags&NodeCheckFlagsEnumValuesComputed != 0) { nodeLinks.flags |= NodeCheckFlagsEnumValuesComputed @@ -24587,8 +24583,6 @@ func (c *Checker) computeConstantEnumMemberValue(member *ast.Node) evaluator.Res c.error(initializer, diagnostics.X_const_enum_member_initializers_must_be_constant_expressions) case member.Parent.Flags&ast.NodeFlagsAmbient != 0: c.error(initializer, diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression) - default: - c.checkTypeAssignableTo(c.checkExpression(initializer), c.numberType, initializer, diagnostics.Type_0_is_not_assignable_to_type_1_as_required_for_computed_enum_member_values) } return result } diff --git a/tsc/internal/checker/inference.go b/tsc/internal/checker/inference.go index 02c7d009b9ec5..d7891e502d318 100644 --- a/tsc/internal/checker/inference.go +++ b/tsc/internal/checker/inference.go @@ -1154,12 +1154,8 @@ func (c *Checker) resolveReverseMappedTypeMembers(t *Type) { } func (c *Checker) getTypeOfReverseMappedSymbol(symbol *ast.Symbol) *Type { - links := c.valueSymbolLinks.Get(symbol) - if links.resolvedType == nil { - reverseLinks := c.ReverseMappedSymbolLinks.Get(symbol) - links.resolvedType = core.OrElse(c.inferReverseMappedType(reverseLinks.propertyType, reverseLinks.mappedType, reverseLinks.constraintType), c.unknownType) - } - return links.resolvedType + reverseLinks := c.ReverseMappedSymbolLinks.Get(symbol) + return core.OrElse(c.inferReverseMappedType(reverseLinks.propertyType, reverseLinks.mappedType, reverseLinks.constraintType), c.unknownType) } // If the original mapped type had an intersection constraint we extract its components, diff --git a/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.errors.txt b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.errors.txt new file mode 100644 index 0000000000000..115bf5bbf4376 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.errors.txt @@ -0,0 +1,14 @@ +circularIndexedPropertyInstantiation.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. +circularIndexedPropertyInstantiation.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'. + + +==== circularIndexedPropertyInstantiation.ts (2 errors) ==== + // Repro from #14837 + + type Foo = { "true": Foo> }[T]; + ~~~~~~ +!!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. + let f1: Foo<"true", {}>; + let f2: Foo<"false", {}>; + ~~~~~~~ +!!! error TS2344: Type '"false"' does not satisfy the constraint '"true"'. \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.js b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.js new file mode 100644 index 0000000000000..ac6aa726ab7a4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/circularIndexedPropertyInstantiation.ts] //// + +//// [circularIndexedPropertyInstantiation.ts] +// Repro from #14837 + +type Foo = { "true": Foo> }[T]; +let f1: Foo<"true", {}>; +let f2: Foo<"false", {}>; + +//// [circularIndexedPropertyInstantiation.js] +"use strict"; +// Repro from #14837 +let f1; +let f2; diff --git a/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.symbols b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.symbols new file mode 100644 index 0000000000000..5473bd4665786 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.symbols @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/circularIndexedPropertyInstantiation.ts] //// + +=== circularIndexedPropertyInstantiation.ts === +// Repro from #14837 + +type Foo = { "true": Foo> }[T]; +>Foo : Symbol(Foo, Decl(circularIndexedPropertyInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(circularIndexedPropertyInstantiation.ts, 2, 9)) +>B : Symbol(B, Decl(circularIndexedPropertyInstantiation.ts, 2, 26)) +>"true" : Symbol("true", Decl(circularIndexedPropertyInstantiation.ts, 2, 33)) +>Foo : Symbol(Foo, Decl(circularIndexedPropertyInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(circularIndexedPropertyInstantiation.ts, 2, 9)) +>Foo : Symbol(Foo, Decl(circularIndexedPropertyInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(circularIndexedPropertyInstantiation.ts, 2, 9)) +>B : Symbol(B, Decl(circularIndexedPropertyInstantiation.ts, 2, 26)) +>T : Symbol(T, Decl(circularIndexedPropertyInstantiation.ts, 2, 9)) + +let f1: Foo<"true", {}>; +>f1 : Symbol(f1, Decl(circularIndexedPropertyInstantiation.ts, 3, 3)) +>Foo : Symbol(Foo, Decl(circularIndexedPropertyInstantiation.ts, 0, 0)) + +let f2: Foo<"false", {}>; +>f2 : Symbol(f2, Decl(circularIndexedPropertyInstantiation.ts, 4, 3)) +>Foo : Symbol(Foo, Decl(circularIndexedPropertyInstantiation.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.types b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.types new file mode 100644 index 0000000000000..789407f9e698b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.types @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/circularIndexedPropertyInstantiation.ts] //// + +=== circularIndexedPropertyInstantiation.ts === +// Repro from #14837 + +type Foo = { "true": Foo> }[T]; +>Foo : Foo +>"true" : Foo> + +let f1: Foo<"true", {}>; +>f1 : any + +let f2: Foo<"false", {}>; +>f2 : unknown + diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).errors.txt b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).errors.txt new file mode 100644 index 0000000000000..0accf5ec5ec5d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).errors.txt @@ -0,0 +1,40 @@ +circularInitializerInference.ts(6,14): error TS2695: Left side of comma operator is unused and has no side effects. +circularInitializerInference.ts(9,20): error TS2695: Left side of comma operator is unused and has no side effects. +circularInitializerInference.ts(9,20): error TS2695: Left side of comma operator is unused and has no side effects. + + +==== circularInitializerInference.ts (3 errors) ==== + export {}; + + type IsAny = 0 extends (1 & Type) ? true : false; + type Assert = Condition; + + var comma = (comma, 3); + ~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + type CommaInference = Assert>; + + var nestedComma = (comma, nestedComma, comma); + ~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + type NestedCommaInference = Assert>; + + var assignment = (assignment = 2); + type AssignmentInference = Assert>; + + var nestedAssignment = (nestedAssignment = nestedAssignment = 2); + type NestedAssignmentInference = Assert>; + + var conditional = conditional ? 0 : 1; + type ConditionalInference = Assert>; + + var logicalAnd = logicalAnd && ""; + type LogicalAndInference = Assert>; + + var propertyAccess = { member: propertyAccess.member }; + type PropertyAccessInference = Assert>; + + const nonCircular: number = 3; + type NonCircularInference = Assert extends false ? true : false>; \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).js b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).js new file mode 100644 index 0000000000000..6b1e6c702f422 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +//// [circularInitializerInference.ts] +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +type Assert = Condition; + +var comma = (comma, 3); +type CommaInference = Assert>; + +var nestedComma = (comma, nestedComma, comma); +type NestedCommaInference = Assert>; + +var assignment = (assignment = 2); +type AssignmentInference = Assert>; + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +type NestedAssignmentInference = Assert>; + +var conditional = conditional ? 0 : 1; +type ConditionalInference = Assert>; + +var logicalAnd = logicalAnd && ""; +type LogicalAndInference = Assert>; + +var propertyAccess = { member: propertyAccess.member }; +type PropertyAccessInference = Assert>; + +const nonCircular: number = 3; +type NonCircularInference = Assert extends false ? true : false>; + +//// [circularInitializerInference.js] +var comma = (comma, 3); +var nestedComma = (comma, nestedComma, comma); +var assignment = (assignment = 2); +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +var conditional = conditional ? 0 : 1; +var logicalAnd = logicalAnd && ""; +var propertyAccess = { member: propertyAccess.member }; +const nonCircular = 3; +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).symbols b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).symbols new file mode 100644 index 0000000000000..7146dd252c8ef --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).symbols @@ -0,0 +1,98 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +=== circularInitializerInference.ts === +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>Type : Symbol(Type, Decl(circularInitializerInference.ts, 2, 11)) +>Type : Symbol(Type, Decl(circularInitializerInference.ts, 2, 11)) + +type Assert = Condition; +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>Condition : Symbol(Condition, Decl(circularInitializerInference.ts, 3, 12)) +>Condition : Symbol(Condition, Decl(circularInitializerInference.ts, 3, 12)) + +var comma = (comma, 3); +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +type CommaInference = Assert>; +>CommaInference : Symbol(CommaInference, Decl(circularInitializerInference.ts, 5, 23)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +var nestedComma = (comma, nestedComma, comma); +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +type NestedCommaInference = Assert>; +>NestedCommaInference : Symbol(NestedCommaInference, Decl(circularInitializerInference.ts, 8, 46)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) + +var assignment = (assignment = 2); +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) + +type AssignmentInference = Assert>; +>AssignmentInference : Symbol(AssignmentInference, Decl(circularInitializerInference.ts, 11, 34)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) + +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : Symbol(NestedAssignmentInference, Decl(circularInitializerInference.ts, 14, 65)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) + +var conditional = conditional ? 0 : 1; +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) + +type ConditionalInference = Assert>; +>ConditionalInference : Symbol(ConditionalInference, Decl(circularInitializerInference.ts, 17, 38)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) + +var logicalAnd = logicalAnd && ""; +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) + +type LogicalAndInference = Assert>; +>LogicalAndInference : Symbol(LogicalAndInference, Decl(circularInitializerInference.ts, 20, 34)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) + +var propertyAccess = { member: propertyAccess.member }; +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) +>member : Symbol(member, Decl(circularInitializerInference.ts, 23, 22)) +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) + +type PropertyAccessInference = Assert>; +>PropertyAccessInference : Symbol(PropertyAccessInference, Decl(circularInitializerInference.ts, 23, 55)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) + +const nonCircular: number = 3; +>nonCircular : Symbol(nonCircular, Decl(circularInitializerInference.ts, 26, 5)) + +type NonCircularInference = Assert extends false ? true : false>; +>NonCircularInference : Symbol(NonCircularInference, Decl(circularInitializerInference.ts, 26, 30)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nonCircular : Symbol(nonCircular, Decl(circularInitializerInference.ts, 26, 5)) + diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).types b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).types new file mode 100644 index 0000000000000..82211d8351e90 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=false).types @@ -0,0 +1,106 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +=== circularInitializerInference.ts === +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : IsAny +>true : true +>false : false + +type Assert = Condition; +>Assert : Condition +>true : true + +var comma = (comma, 3); +>comma : any +>(comma, 3) : 3 +>comma, 3 : 3 +>comma : any +>3 : 3 + +type CommaInference = Assert>; +>CommaInference : any +>comma : any + +var nestedComma = (comma, nestedComma, comma); +>nestedComma : any +>(comma, nestedComma, comma) : any +>comma, nestedComma, comma : any +>comma, nestedComma : any +>comma : any +>nestedComma : any +>comma : any + +type NestedCommaInference = Assert>; +>NestedCommaInference : any +>nestedComma : any + +var assignment = (assignment = 2); +>assignment : any +>(assignment = 2) : 2 +>assignment = 2 : 2 +>assignment : any +>2 : 2 + +type AssignmentInference = Assert>; +>AssignmentInference : any +>assignment : any + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +>nestedAssignment : any +>(nestedAssignment = nestedAssignment = 2) : 2 +>nestedAssignment = nestedAssignment = 2 : 2 +>nestedAssignment : any +>nestedAssignment = 2 : 2 +>nestedAssignment : any +>2 : 2 + +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : any +>nestedAssignment : any + +var conditional = conditional ? 0 : 1; +>conditional : any +>conditional ? 0 : 1 : 0 | 1 +>conditional : any +>0 : 0 +>1 : 1 + +type ConditionalInference = Assert>; +>ConditionalInference : any +>conditional : any + +var logicalAnd = logicalAnd && ""; +>logicalAnd : any +>logicalAnd && "" : "" +>logicalAnd : any +>"" : "" + +type LogicalAndInference = Assert>; +>LogicalAndInference : any +>logicalAnd : any + +var propertyAccess = { member: propertyAccess.member }; +>propertyAccess : any +>{ member: propertyAccess.member } : { member: any; } +>member : any +>propertyAccess.member : any +>propertyAccess : any +>member : any + +type PropertyAccessInference = Assert>; +>PropertyAccessInference : any +>propertyAccess : any + +const nonCircular: number = 3; +>nonCircular : number +>3 : 3 + +type NonCircularInference = Assert extends false ? true : false>; +>NonCircularInference : true +>nonCircular : number +>false : false +>true : true +>false : false + diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).errors.txt b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).errors.txt new file mode 100644 index 0000000000000..f7f94d4a4b3bc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).errors.txt @@ -0,0 +1,61 @@ +circularInitializerInference.ts(6,5): error TS7022: 'comma' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(6,14): error TS2695: Left side of comma operator is unused and has no side effects. +circularInitializerInference.ts(9,5): error TS7022: 'nestedComma' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(9,20): error TS2695: Left side of comma operator is unused and has no side effects. +circularInitializerInference.ts(9,20): error TS2695: Left side of comma operator is unused and has no side effects. +circularInitializerInference.ts(12,5): error TS7022: 'assignment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(15,5): error TS7022: 'nestedAssignment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(18,5): error TS7022: 'conditional' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(21,5): error TS7022: 'logicalAnd' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +circularInitializerInference.ts(24,5): error TS7022: 'propertyAccess' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== circularInitializerInference.ts (10 errors) ==== + export {}; + + type IsAny = 0 extends (1 & Type) ? true : false; + type Assert = Condition; + + var comma = (comma, 3); + ~~~~~ +!!! error TS7022: 'comma' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + type CommaInference = Assert>; + + var nestedComma = (comma, nestedComma, comma); + ~~~~~~~~~~~ +!!! error TS7022: 'nestedComma' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + type NestedCommaInference = Assert>; + + var assignment = (assignment = 2); + ~~~~~~~~~~ +!!! error TS7022: 'assignment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + type AssignmentInference = Assert>; + + var nestedAssignment = (nestedAssignment = nestedAssignment = 2); + ~~~~~~~~~~~~~~~~ +!!! error TS7022: 'nestedAssignment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + type NestedAssignmentInference = Assert>; + + var conditional = conditional ? 0 : 1; + ~~~~~~~~~~~ +!!! error TS7022: 'conditional' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + type ConditionalInference = Assert>; + + var logicalAnd = logicalAnd && ""; + ~~~~~~~~~~ +!!! error TS7022: 'logicalAnd' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + type LogicalAndInference = Assert>; + + var propertyAccess = { member: propertyAccess.member }; + ~~~~~~~~~~~~~~ +!!! error TS7022: 'propertyAccess' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + type PropertyAccessInference = Assert>; + + const nonCircular: number = 3; + type NonCircularInference = Assert extends false ? true : false>; \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).js b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).js new file mode 100644 index 0000000000000..6b1e6c702f422 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +//// [circularInitializerInference.ts] +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +type Assert = Condition; + +var comma = (comma, 3); +type CommaInference = Assert>; + +var nestedComma = (comma, nestedComma, comma); +type NestedCommaInference = Assert>; + +var assignment = (assignment = 2); +type AssignmentInference = Assert>; + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +type NestedAssignmentInference = Assert>; + +var conditional = conditional ? 0 : 1; +type ConditionalInference = Assert>; + +var logicalAnd = logicalAnd && ""; +type LogicalAndInference = Assert>; + +var propertyAccess = { member: propertyAccess.member }; +type PropertyAccessInference = Assert>; + +const nonCircular: number = 3; +type NonCircularInference = Assert extends false ? true : false>; + +//// [circularInitializerInference.js] +var comma = (comma, 3); +var nestedComma = (comma, nestedComma, comma); +var assignment = (assignment = 2); +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +var conditional = conditional ? 0 : 1; +var logicalAnd = logicalAnd && ""; +var propertyAccess = { member: propertyAccess.member }; +const nonCircular = 3; +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).symbols b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).symbols new file mode 100644 index 0000000000000..7146dd252c8ef --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).symbols @@ -0,0 +1,98 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +=== circularInitializerInference.ts === +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>Type : Symbol(Type, Decl(circularInitializerInference.ts, 2, 11)) +>Type : Symbol(Type, Decl(circularInitializerInference.ts, 2, 11)) + +type Assert = Condition; +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>Condition : Symbol(Condition, Decl(circularInitializerInference.ts, 3, 12)) +>Condition : Symbol(Condition, Decl(circularInitializerInference.ts, 3, 12)) + +var comma = (comma, 3); +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +type CommaInference = Assert>; +>CommaInference : Symbol(CommaInference, Decl(circularInitializerInference.ts, 5, 23)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +var nestedComma = (comma, nestedComma, comma); +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) +>comma : Symbol(comma, Decl(circularInitializerInference.ts, 5, 3)) + +type NestedCommaInference = Assert>; +>NestedCommaInference : Symbol(NestedCommaInference, Decl(circularInitializerInference.ts, 8, 46)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nestedComma : Symbol(nestedComma, Decl(circularInitializerInference.ts, 8, 3)) + +var assignment = (assignment = 2); +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) + +type AssignmentInference = Assert>; +>AssignmentInference : Symbol(AssignmentInference, Decl(circularInitializerInference.ts, 11, 34)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>assignment : Symbol(assignment, Decl(circularInitializerInference.ts, 11, 3)) + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) + +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : Symbol(NestedAssignmentInference, Decl(circularInitializerInference.ts, 14, 65)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nestedAssignment : Symbol(nestedAssignment, Decl(circularInitializerInference.ts, 14, 3)) + +var conditional = conditional ? 0 : 1; +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) + +type ConditionalInference = Assert>; +>ConditionalInference : Symbol(ConditionalInference, Decl(circularInitializerInference.ts, 17, 38)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>conditional : Symbol(conditional, Decl(circularInitializerInference.ts, 17, 3)) + +var logicalAnd = logicalAnd && ""; +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) + +type LogicalAndInference = Assert>; +>LogicalAndInference : Symbol(LogicalAndInference, Decl(circularInitializerInference.ts, 20, 34)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>logicalAnd : Symbol(logicalAnd, Decl(circularInitializerInference.ts, 20, 3)) + +var propertyAccess = { member: propertyAccess.member }; +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) +>member : Symbol(member, Decl(circularInitializerInference.ts, 23, 22)) +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) + +type PropertyAccessInference = Assert>; +>PropertyAccessInference : Symbol(PropertyAccessInference, Decl(circularInitializerInference.ts, 23, 55)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>propertyAccess : Symbol(propertyAccess, Decl(circularInitializerInference.ts, 23, 3)) + +const nonCircular: number = 3; +>nonCircular : Symbol(nonCircular, Decl(circularInitializerInference.ts, 26, 5)) + +type NonCircularInference = Assert extends false ? true : false>; +>NonCircularInference : Symbol(NonCircularInference, Decl(circularInitializerInference.ts, 26, 30)) +>Assert : Symbol(Assert, Decl(circularInitializerInference.ts, 2, 55)) +>IsAny : Symbol(IsAny, Decl(circularInitializerInference.ts, 0, 10)) +>nonCircular : Symbol(nonCircular, Decl(circularInitializerInference.ts, 26, 5)) + diff --git a/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).types b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).types new file mode 100644 index 0000000000000..604557d2afa9b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/circularInitializerInference(strict=true).types @@ -0,0 +1,106 @@ +//// [tests/cases/compiler/circularInitializerInference.ts] //// + +=== circularInitializerInference.ts === +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : IsAny +>true : true +>false : false + +type Assert = Condition; +>Assert : Condition +>true : true + +var comma = (comma, 3); +>comma : any +>(comma, 3) : 3 +>comma, 3 : 3 +>comma : any +>3 : 3 + +type CommaInference = Assert>; +>CommaInference : any +>comma : any + +var nestedComma = (comma, nestedComma, comma); +>nestedComma : any +>(comma, nestedComma, comma) : any +>comma, nestedComma, comma : any +>comma, nestedComma : any +>comma : any +>nestedComma : any +>comma : any + +type NestedCommaInference = Assert>; +>NestedCommaInference : any +>nestedComma : any + +var assignment = (assignment = 2); +>assignment : any +>(assignment = 2) : 2 +>assignment = 2 : 2 +>assignment : any +>2 : 2 + +type AssignmentInference = Assert>; +>AssignmentInference : any +>assignment : any + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +>nestedAssignment : any +>(nestedAssignment = nestedAssignment = 2) : 2 +>nestedAssignment = nestedAssignment = 2 : 2 +>nestedAssignment : any +>nestedAssignment = 2 : 2 +>nestedAssignment : any +>2 : 2 + +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : any +>nestedAssignment : any + +var conditional = conditional ? 0 : 1; +>conditional : any +>conditional ? 0 : 1 : 0 | 1 +>conditional : any +>0 : 0 +>1 : 1 + +type ConditionalInference = Assert>; +>ConditionalInference : any +>conditional : any + +var logicalAnd = logicalAnd && ""; +>logicalAnd : any +>logicalAnd && "" : any +>logicalAnd : any +>"" : "" + +type LogicalAndInference = Assert>; +>LogicalAndInference : any +>logicalAnd : any + +var propertyAccess = { member: propertyAccess.member }; +>propertyAccess : any +>{ member: propertyAccess.member } : { member: any; } +>member : any +>propertyAccess.member : any +>propertyAccess : any +>member : any + +type PropertyAccessInference = Assert>; +>PropertyAccessInference : any +>propertyAccess : any + +const nonCircular: number = 3; +>nonCircular : number +>3 : 3 + +type NonCircularInference = Assert extends false ? true : false>; +>NonCircularInference : true +>nonCircular : number +>false : false +>true : true +>false : false + diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).errors.txt b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).errors.txt new file mode 100644 index 0000000000000..e6a85a2793754 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).errors.txt @@ -0,0 +1,80 @@ +classCircularityDiagnostics.ts(1,7): error TS2506: 'Direct' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(9,7): error TS2506: 'First' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(9,21): error TS2449: Class 'Second' used before its declaration. +classCircularityDiagnostics.ts(10,7): error TS2506: 'Second' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(12,26): error TS2506: 'Named' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(23,16): error TS2448: Block-scoped variable 'SelfReferencingBase' used before its declaration. +classCircularityDiagnostics.ts(41,44): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +classCircularityDiagnostics.ts(42,58): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +classCircularityDiagnostics.ts(45,34): error TS2507: Type 'number' is not a constructor function type. +classCircularityDiagnostics.ts(45,50): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + +==== classCircularityDiagnostics.ts (10 errors) ==== + class Direct extends Direct { + ~~~~~~ +!!! error TS2506: 'Direct' is referenced directly or indirectly in its own base expression. + static value = 1; + value = 2; + } + + const staticValue = Direct.value; + const instanceValue = new Direct().value; + + class First extends Second {} + ~~~~~ +!!! error TS2506: 'First' is referenced directly or indirectly in its own base expression. + ~~~~~~ +!!! error TS2449: Class 'Second' used before its declaration. +!!! related TS2728 classCircularityDiagnostics.ts:10:7: 'Second' is declared here. + class Second extends First {} + ~~~~~~ +!!! error TS2506: 'Second' is referenced directly or indirectly in its own base expression. + + const Expression = class Named extends Named {}; + ~~~~~ +!!! error TS2506: 'Named' is referenced directly or indirectly in its own base expression. + + class NestedBase extends (class { + static value = 1; + value = 2; + }) {} + + const nestedStaticValue: number = NestedBase.value; + const nestedInstanceValue: number = new NestedBase().value; + + const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2448: Block-scoped variable 'SelfReferencingBase' used before its declaration. +!!! related TS2728 classCircularityDiagnostics.ts:22:7: 'SelfReferencingBase' is declared here. + }) {}; + + const selfConstructor = SelfReferencingBase.self; + + function mixin {}>(base: Base) { + return class extends base { + static value = 1; + value = 2; + }; + } + + class Mixed extends mixin(NestedBase) {} + + const mixedStaticValue: number = Mixed.value; + const mixedInstanceValue: number = new Mixed().value; + + declare function makeBase(value: number): typeof NestedBase; + class InvalidBaseArgument extends makeBase("invalid") {} + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + const InvalidExpressionArgument = class extends makeBase("invalid") {}; + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + declare function makeInvalidBase(value: number): number; + class InvalidConstructor extends makeInvalidBase("invalid") {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2507: Type 'number' is not a constructor function type. + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).js b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).js new file mode 100644 index 0000000000000..2ff93ac2eb65b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).js @@ -0,0 +1,91 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +//// [classCircularityDiagnostics.ts] +class Direct extends Direct { + static value = 1; + value = 2; +} + +const staticValue = Direct.value; +const instanceValue = new Direct().value; + +class First extends Second {} +class Second extends First {} + +const Expression = class Named extends Named {}; + +class NestedBase extends (class { + static value = 1; + value = 2; +}) {} + +const nestedStaticValue: number = NestedBase.value; +const nestedInstanceValue: number = new NestedBase().value; + +const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; +}) {}; + +const selfConstructor = SelfReferencingBase.self; + +function mixin {}>(base: Base) { + return class extends base { + static value = 1; + value = 2; + }; +} + +class Mixed extends mixin(NestedBase) {} + +const mixedStaticValue: number = Mixed.value; +const mixedInstanceValue: number = new Mixed().value; + +declare function makeBase(value: number): typeof NestedBase; +class InvalidBaseArgument extends makeBase("invalid") {} +const InvalidExpressionArgument = class extends makeBase("invalid") {}; + +declare function makeInvalidBase(value: number): number; +class InvalidConstructor extends makeInvalidBase("invalid") {} + +//// [classCircularityDiagnostics.js] +"use strict"; +class Direct extends Direct { + static value = 1; + value = 2; +} +const staticValue = Direct.value; +const instanceValue = new Direct().value; +class First extends Second { +} +class Second extends First { +} +const Expression = class Named extends Named { +}; +class NestedBase extends (class { + static value = 1; + value = 2; +}) { +} +const nestedStaticValue = NestedBase.value; +const nestedInstanceValue = new NestedBase().value; +const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; +}) { +}; +const selfConstructor = SelfReferencingBase.self; +function mixin(base) { + return class extends base { + static value = 1; + value = 2; + }; +} +class Mixed extends mixin(NestedBase) { +} +const mixedStaticValue = Mixed.value; +const mixedInstanceValue = new Mixed().value; +class InvalidBaseArgument extends makeBase("invalid") { +} +const InvalidExpressionArgument = class extends makeBase("invalid") { +}; +class InvalidConstructor extends makeInvalidBase("invalid") { +} diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).symbols b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).symbols new file mode 100644 index 0000000000000..9e892a1edd0ab --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).symbols @@ -0,0 +1,134 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +=== classCircularityDiagnostics.ts === +class Direct extends Direct { +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) + + static value = 1; +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) + + value = 2; +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) +} + +const staticValue = Direct.value; +>staticValue : Symbol(staticValue, Decl(classCircularityDiagnostics.ts, 5, 5)) +>Direct.value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) + +const instanceValue = new Direct().value; +>instanceValue : Symbol(instanceValue, Decl(classCircularityDiagnostics.ts, 6, 5)) +>new Direct().value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) + +class First extends Second {} +>First : Symbol(First, Decl(classCircularityDiagnostics.ts, 6, 41)) +>Second : Symbol(Second, Decl(classCircularityDiagnostics.ts, 8, 29)) + +class Second extends First {} +>Second : Symbol(Second, Decl(classCircularityDiagnostics.ts, 8, 29)) +>First : Symbol(First, Decl(classCircularityDiagnostics.ts, 6, 41)) + +const Expression = class Named extends Named {}; +>Expression : Symbol(Expression, Decl(classCircularityDiagnostics.ts, 11, 5)) +>Named : Symbol(Named, Decl(classCircularityDiagnostics.ts, 11, 18)) +>Named : Symbol(Named, Decl(classCircularityDiagnostics.ts, 11, 18)) + +class NestedBase extends (class { +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + + static value = 1; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) + + value = 2; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) + +}) {} + +const nestedStaticValue: number = NestedBase.value; +>nestedStaticValue : Symbol(nestedStaticValue, Decl(classCircularityDiagnostics.ts, 18, 5)) +>NestedBase.value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) + +const nestedInstanceValue: number = new NestedBase().value; +>nestedInstanceValue : Symbol(nestedInstanceValue, Decl(classCircularityDiagnostics.ts, 19, 5)) +>new NestedBase().value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) + +const SelfReferencingBase = class extends (class { +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) + + static self = SelfReferencingBase; +>self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) + +}) {}; + +const selfConstructor = SelfReferencingBase.self; +>selfConstructor : Symbol(selfConstructor, Decl(classCircularityDiagnostics.ts, 25, 5)) +>SelfReferencingBase.self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) +>self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) + +function mixin {}>(base: Base) { +>mixin : Symbol(mixin, Decl(classCircularityDiagnostics.ts, 25, 49)) +>Base : Symbol(Base, Decl(classCircularityDiagnostics.ts, 27, 15)) +>args : Symbol(args, Decl(classCircularityDiagnostics.ts, 27, 33)) +>base : Symbol(base, Decl(classCircularityDiagnostics.ts, 27, 56)) +>Base : Symbol(Base, Decl(classCircularityDiagnostics.ts, 27, 15)) + + return class extends base { +>base : Symbol(base, Decl(classCircularityDiagnostics.ts, 27, 56)) + + static value = 1; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 28, 28)) + + value = 2; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 29, 19)) + + }; +} + +class Mixed extends mixin(NestedBase) {} +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>mixin : Symbol(mixin, Decl(classCircularityDiagnostics.ts, 25, 49)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + +const mixedStaticValue: number = Mixed.value; +>mixedStaticValue : Symbol(mixedStaticValue, Decl(classCircularityDiagnostics.ts, 36, 5)) +>Mixed.value : Symbol(value, Decl(classCircularityDiagnostics.ts, 28, 28), Decl(classCircularityDiagnostics.ts, 13, 33)) +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 28, 28), Decl(classCircularityDiagnostics.ts, 13, 33)) + +const mixedInstanceValue: number = new Mixed().value; +>mixedInstanceValue : Symbol(mixedInstanceValue, Decl(classCircularityDiagnostics.ts, 37, 5)) +>new Mixed().value : Symbol(value, Decl(classCircularityDiagnostics.ts, 29, 19), Decl(classCircularityDiagnostics.ts, 14, 18)) +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 29, 19), Decl(classCircularityDiagnostics.ts, 14, 18)) + +declare function makeBase(value: number): typeof NestedBase; +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 39, 26)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + +class InvalidBaseArgument extends makeBase("invalid") {} +>InvalidBaseArgument : Symbol(InvalidBaseArgument, Decl(classCircularityDiagnostics.ts, 39, 60)) +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) + +const InvalidExpressionArgument = class extends makeBase("invalid") {}; +>InvalidExpressionArgument : Symbol(InvalidExpressionArgument, Decl(classCircularityDiagnostics.ts, 41, 5)) +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) + +declare function makeInvalidBase(value: number): number; +>makeInvalidBase : Symbol(makeInvalidBase, Decl(classCircularityDiagnostics.ts, 41, 71)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 43, 33)) + +class InvalidConstructor extends makeInvalidBase("invalid") {} +>InvalidConstructor : Symbol(InvalidConstructor, Decl(classCircularityDiagnostics.ts, 43, 56)) +>makeInvalidBase : Symbol(makeInvalidBase, Decl(classCircularityDiagnostics.ts, 41, 71)) + diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).types b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).types new file mode 100644 index 0000000000000..0b46eec400402 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=false).types @@ -0,0 +1,156 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +=== classCircularityDiagnostics.ts === +class Direct extends Direct { +>Direct : Direct +>Direct : typeof Direct + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 +} + +const staticValue = Direct.value; +>staticValue : number +>Direct.value : number +>Direct : typeof Direct +>value : number + +const instanceValue = new Direct().value; +>instanceValue : number +>new Direct().value : number +>new Direct() : Direct +>Direct : typeof Direct +>value : number + +class First extends Second {} +>First : First +>Second : typeof Second + +class Second extends First {} +>Second : Second +>First : typeof First + +const Expression = class Named extends Named {}; +>Expression : typeof Named +>class Named extends Named {} : typeof Named +>Named : typeof Named +>Named : typeof Named + +class NestedBase extends (class { +>NestedBase : NestedBase +>(class { static value = 1; value = 2;}) : (Anonymous class) +>class { static value = 1; value = 2;} : typeof (Anonymous class) + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 + +}) {} + +const nestedStaticValue: number = NestedBase.value; +>nestedStaticValue : number +>NestedBase.value : number +>NestedBase : typeof NestedBase +>value : number + +const nestedInstanceValue: number = new NestedBase().value; +>nestedInstanceValue : number +>new NestedBase().value : number +>new NestedBase() : NestedBase +>NestedBase : typeof NestedBase +>value : number + +const SelfReferencingBase = class extends (class { +>SelfReferencingBase : typeof SelfReferencingBase +>class extends (class { static self = SelfReferencingBase;}) {} : typeof SelfReferencingBase +>(class { static self = SelfReferencingBase;}) : (Anonymous class) +>class { static self = SelfReferencingBase;} : typeof (Anonymous class) + + static self = SelfReferencingBase; +>self : typeof SelfReferencingBase +>SelfReferencingBase : typeof SelfReferencingBase + +}) {}; + +const selfConstructor = SelfReferencingBase.self; +>selfConstructor : typeof SelfReferencingBase +>SelfReferencingBase.self : typeof SelfReferencingBase +>SelfReferencingBase : typeof SelfReferencingBase +>self : typeof SelfReferencingBase + +function mixin {}>(base: Base) { +>mixin : {}>(base: Base) => { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>args : any[] +>base : Base + + return class extends base { +>class extends base { static value = 1; value = 2; } : { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>base : {} + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 + + }; +} + +class Mixed extends mixin(NestedBase) {} +>Mixed : Mixed +>mixin(NestedBase) : mixin.(Anonymous class) & NestedBase +>mixin : {}>(base: Base) => { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>NestedBase : typeof NestedBase + +const mixedStaticValue: number = Mixed.value; +>mixedStaticValue : number +>Mixed.value : number +>Mixed : typeof Mixed +>value : number + +const mixedInstanceValue: number = new Mixed().value; +>mixedInstanceValue : number +>new Mixed().value : number +>new Mixed() : Mixed +>Mixed : typeof Mixed +>value : number + +declare function makeBase(value: number): typeof NestedBase; +>makeBase : (value: number) => typeof NestedBase +>value : number +>NestedBase : typeof NestedBase + +class InvalidBaseArgument extends makeBase("invalid") {} +>InvalidBaseArgument : InvalidBaseArgument +>makeBase("invalid") : NestedBase +>makeBase : (value: number) => typeof NestedBase +>"invalid" : "invalid" + +const InvalidExpressionArgument = class extends makeBase("invalid") {}; +>InvalidExpressionArgument : typeof InvalidExpressionArgument +>class extends makeBase("invalid") {} : typeof InvalidExpressionArgument +>makeBase("invalid") : NestedBase +>makeBase : (value: number) => typeof NestedBase +>"invalid" : "invalid" + +declare function makeInvalidBase(value: number): number; +>makeInvalidBase : (value: number) => number +>value : number + +class InvalidConstructor extends makeInvalidBase("invalid") {} +>InvalidConstructor : InvalidConstructor +>makeInvalidBase("invalid") : number +>makeInvalidBase : (value: number) => number +>"invalid" : "invalid" + diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).errors.txt b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).errors.txt new file mode 100644 index 0000000000000..e6a85a2793754 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).errors.txt @@ -0,0 +1,80 @@ +classCircularityDiagnostics.ts(1,7): error TS2506: 'Direct' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(9,7): error TS2506: 'First' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(9,21): error TS2449: Class 'Second' used before its declaration. +classCircularityDiagnostics.ts(10,7): error TS2506: 'Second' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(12,26): error TS2506: 'Named' is referenced directly or indirectly in its own base expression. +classCircularityDiagnostics.ts(23,16): error TS2448: Block-scoped variable 'SelfReferencingBase' used before its declaration. +classCircularityDiagnostics.ts(41,44): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +classCircularityDiagnostics.ts(42,58): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +classCircularityDiagnostics.ts(45,34): error TS2507: Type 'number' is not a constructor function type. +classCircularityDiagnostics.ts(45,50): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + +==== classCircularityDiagnostics.ts (10 errors) ==== + class Direct extends Direct { + ~~~~~~ +!!! error TS2506: 'Direct' is referenced directly or indirectly in its own base expression. + static value = 1; + value = 2; + } + + const staticValue = Direct.value; + const instanceValue = new Direct().value; + + class First extends Second {} + ~~~~~ +!!! error TS2506: 'First' is referenced directly or indirectly in its own base expression. + ~~~~~~ +!!! error TS2449: Class 'Second' used before its declaration. +!!! related TS2728 classCircularityDiagnostics.ts:10:7: 'Second' is declared here. + class Second extends First {} + ~~~~~~ +!!! error TS2506: 'Second' is referenced directly or indirectly in its own base expression. + + const Expression = class Named extends Named {}; + ~~~~~ +!!! error TS2506: 'Named' is referenced directly or indirectly in its own base expression. + + class NestedBase extends (class { + static value = 1; + value = 2; + }) {} + + const nestedStaticValue: number = NestedBase.value; + const nestedInstanceValue: number = new NestedBase().value; + + const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2448: Block-scoped variable 'SelfReferencingBase' used before its declaration. +!!! related TS2728 classCircularityDiagnostics.ts:22:7: 'SelfReferencingBase' is declared here. + }) {}; + + const selfConstructor = SelfReferencingBase.self; + + function mixin {}>(base: Base) { + return class extends base { + static value = 1; + value = 2; + }; + } + + class Mixed extends mixin(NestedBase) {} + + const mixedStaticValue: number = Mixed.value; + const mixedInstanceValue: number = new Mixed().value; + + declare function makeBase(value: number): typeof NestedBase; + class InvalidBaseArgument extends makeBase("invalid") {} + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + const InvalidExpressionArgument = class extends makeBase("invalid") {}; + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + declare function makeInvalidBase(value: number): number; + class InvalidConstructor extends makeInvalidBase("invalid") {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2507: Type 'number' is not a constructor function type. + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).js b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).js new file mode 100644 index 0000000000000..2ff93ac2eb65b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).js @@ -0,0 +1,91 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +//// [classCircularityDiagnostics.ts] +class Direct extends Direct { + static value = 1; + value = 2; +} + +const staticValue = Direct.value; +const instanceValue = new Direct().value; + +class First extends Second {} +class Second extends First {} + +const Expression = class Named extends Named {}; + +class NestedBase extends (class { + static value = 1; + value = 2; +}) {} + +const nestedStaticValue: number = NestedBase.value; +const nestedInstanceValue: number = new NestedBase().value; + +const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; +}) {}; + +const selfConstructor = SelfReferencingBase.self; + +function mixin {}>(base: Base) { + return class extends base { + static value = 1; + value = 2; + }; +} + +class Mixed extends mixin(NestedBase) {} + +const mixedStaticValue: number = Mixed.value; +const mixedInstanceValue: number = new Mixed().value; + +declare function makeBase(value: number): typeof NestedBase; +class InvalidBaseArgument extends makeBase("invalid") {} +const InvalidExpressionArgument = class extends makeBase("invalid") {}; + +declare function makeInvalidBase(value: number): number; +class InvalidConstructor extends makeInvalidBase("invalid") {} + +//// [classCircularityDiagnostics.js] +"use strict"; +class Direct extends Direct { + static value = 1; + value = 2; +} +const staticValue = Direct.value; +const instanceValue = new Direct().value; +class First extends Second { +} +class Second extends First { +} +const Expression = class Named extends Named { +}; +class NestedBase extends (class { + static value = 1; + value = 2; +}) { +} +const nestedStaticValue = NestedBase.value; +const nestedInstanceValue = new NestedBase().value; +const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; +}) { +}; +const selfConstructor = SelfReferencingBase.self; +function mixin(base) { + return class extends base { + static value = 1; + value = 2; + }; +} +class Mixed extends mixin(NestedBase) { +} +const mixedStaticValue = Mixed.value; +const mixedInstanceValue = new Mixed().value; +class InvalidBaseArgument extends makeBase("invalid") { +} +const InvalidExpressionArgument = class extends makeBase("invalid") { +}; +class InvalidConstructor extends makeInvalidBase("invalid") { +} diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).symbols b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).symbols new file mode 100644 index 0000000000000..9e892a1edd0ab --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).symbols @@ -0,0 +1,134 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +=== classCircularityDiagnostics.ts === +class Direct extends Direct { +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) + + static value = 1; +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) + + value = 2; +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) +} + +const staticValue = Direct.value; +>staticValue : Symbol(staticValue, Decl(classCircularityDiagnostics.ts, 5, 5)) +>Direct.value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 0, 29)) + +const instanceValue = new Direct().value; +>instanceValue : Symbol(instanceValue, Decl(classCircularityDiagnostics.ts, 6, 5)) +>new Direct().value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) +>Direct : Symbol(Direct, Decl(classCircularityDiagnostics.ts, 0, 0)) +>value : Symbol(Direct.value, Decl(classCircularityDiagnostics.ts, 1, 18)) + +class First extends Second {} +>First : Symbol(First, Decl(classCircularityDiagnostics.ts, 6, 41)) +>Second : Symbol(Second, Decl(classCircularityDiagnostics.ts, 8, 29)) + +class Second extends First {} +>Second : Symbol(Second, Decl(classCircularityDiagnostics.ts, 8, 29)) +>First : Symbol(First, Decl(classCircularityDiagnostics.ts, 6, 41)) + +const Expression = class Named extends Named {}; +>Expression : Symbol(Expression, Decl(classCircularityDiagnostics.ts, 11, 5)) +>Named : Symbol(Named, Decl(classCircularityDiagnostics.ts, 11, 18)) +>Named : Symbol(Named, Decl(classCircularityDiagnostics.ts, 11, 18)) + +class NestedBase extends (class { +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + + static value = 1; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) + + value = 2; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) + +}) {} + +const nestedStaticValue: number = NestedBase.value; +>nestedStaticValue : Symbol(nestedStaticValue, Decl(classCircularityDiagnostics.ts, 18, 5)) +>NestedBase.value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 13, 33)) + +const nestedInstanceValue: number = new NestedBase().value; +>nestedInstanceValue : Symbol(nestedInstanceValue, Decl(classCircularityDiagnostics.ts, 19, 5)) +>new NestedBase().value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 14, 18)) + +const SelfReferencingBase = class extends (class { +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) + + static self = SelfReferencingBase; +>self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) + +}) {}; + +const selfConstructor = SelfReferencingBase.self; +>selfConstructor : Symbol(selfConstructor, Decl(classCircularityDiagnostics.ts, 25, 5)) +>SelfReferencingBase.self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) +>SelfReferencingBase : Symbol(SelfReferencingBase, Decl(classCircularityDiagnostics.ts, 21, 5)) +>self : Symbol((Anonymous class).self, Decl(classCircularityDiagnostics.ts, 21, 50)) + +function mixin {}>(base: Base) { +>mixin : Symbol(mixin, Decl(classCircularityDiagnostics.ts, 25, 49)) +>Base : Symbol(Base, Decl(classCircularityDiagnostics.ts, 27, 15)) +>args : Symbol(args, Decl(classCircularityDiagnostics.ts, 27, 33)) +>base : Symbol(base, Decl(classCircularityDiagnostics.ts, 27, 56)) +>Base : Symbol(Base, Decl(classCircularityDiagnostics.ts, 27, 15)) + + return class extends base { +>base : Symbol(base, Decl(classCircularityDiagnostics.ts, 27, 56)) + + static value = 1; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 28, 28)) + + value = 2; +>value : Symbol((Anonymous class).value, Decl(classCircularityDiagnostics.ts, 29, 19)) + + }; +} + +class Mixed extends mixin(NestedBase) {} +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>mixin : Symbol(mixin, Decl(classCircularityDiagnostics.ts, 25, 49)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + +const mixedStaticValue: number = Mixed.value; +>mixedStaticValue : Symbol(mixedStaticValue, Decl(classCircularityDiagnostics.ts, 36, 5)) +>Mixed.value : Symbol(value, Decl(classCircularityDiagnostics.ts, 28, 28), Decl(classCircularityDiagnostics.ts, 13, 33)) +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 28, 28), Decl(classCircularityDiagnostics.ts, 13, 33)) + +const mixedInstanceValue: number = new Mixed().value; +>mixedInstanceValue : Symbol(mixedInstanceValue, Decl(classCircularityDiagnostics.ts, 37, 5)) +>new Mixed().value : Symbol(value, Decl(classCircularityDiagnostics.ts, 29, 19), Decl(classCircularityDiagnostics.ts, 14, 18)) +>Mixed : Symbol(Mixed, Decl(classCircularityDiagnostics.ts, 32, 1)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 29, 19), Decl(classCircularityDiagnostics.ts, 14, 18)) + +declare function makeBase(value: number): typeof NestedBase; +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 39, 26)) +>NestedBase : Symbol(NestedBase, Decl(classCircularityDiagnostics.ts, 11, 48)) + +class InvalidBaseArgument extends makeBase("invalid") {} +>InvalidBaseArgument : Symbol(InvalidBaseArgument, Decl(classCircularityDiagnostics.ts, 39, 60)) +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) + +const InvalidExpressionArgument = class extends makeBase("invalid") {}; +>InvalidExpressionArgument : Symbol(InvalidExpressionArgument, Decl(classCircularityDiagnostics.ts, 41, 5)) +>makeBase : Symbol(makeBase, Decl(classCircularityDiagnostics.ts, 37, 53)) + +declare function makeInvalidBase(value: number): number; +>makeInvalidBase : Symbol(makeInvalidBase, Decl(classCircularityDiagnostics.ts, 41, 71)) +>value : Symbol(value, Decl(classCircularityDiagnostics.ts, 43, 33)) + +class InvalidConstructor extends makeInvalidBase("invalid") {} +>InvalidConstructor : Symbol(InvalidConstructor, Decl(classCircularityDiagnostics.ts, 43, 56)) +>makeInvalidBase : Symbol(makeInvalidBase, Decl(classCircularityDiagnostics.ts, 41, 71)) + diff --git a/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).types b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).types new file mode 100644 index 0000000000000..0b46eec400402 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/classCircularityDiagnostics(noimplicitany=true).types @@ -0,0 +1,156 @@ +//// [tests/cases/compiler/classCircularityDiagnostics.ts] //// + +=== classCircularityDiagnostics.ts === +class Direct extends Direct { +>Direct : Direct +>Direct : typeof Direct + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 +} + +const staticValue = Direct.value; +>staticValue : number +>Direct.value : number +>Direct : typeof Direct +>value : number + +const instanceValue = new Direct().value; +>instanceValue : number +>new Direct().value : number +>new Direct() : Direct +>Direct : typeof Direct +>value : number + +class First extends Second {} +>First : First +>Second : typeof Second + +class Second extends First {} +>Second : Second +>First : typeof First + +const Expression = class Named extends Named {}; +>Expression : typeof Named +>class Named extends Named {} : typeof Named +>Named : typeof Named +>Named : typeof Named + +class NestedBase extends (class { +>NestedBase : NestedBase +>(class { static value = 1; value = 2;}) : (Anonymous class) +>class { static value = 1; value = 2;} : typeof (Anonymous class) + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 + +}) {} + +const nestedStaticValue: number = NestedBase.value; +>nestedStaticValue : number +>NestedBase.value : number +>NestedBase : typeof NestedBase +>value : number + +const nestedInstanceValue: number = new NestedBase().value; +>nestedInstanceValue : number +>new NestedBase().value : number +>new NestedBase() : NestedBase +>NestedBase : typeof NestedBase +>value : number + +const SelfReferencingBase = class extends (class { +>SelfReferencingBase : typeof SelfReferencingBase +>class extends (class { static self = SelfReferencingBase;}) {} : typeof SelfReferencingBase +>(class { static self = SelfReferencingBase;}) : (Anonymous class) +>class { static self = SelfReferencingBase;} : typeof (Anonymous class) + + static self = SelfReferencingBase; +>self : typeof SelfReferencingBase +>SelfReferencingBase : typeof SelfReferencingBase + +}) {}; + +const selfConstructor = SelfReferencingBase.self; +>selfConstructor : typeof SelfReferencingBase +>SelfReferencingBase.self : typeof SelfReferencingBase +>SelfReferencingBase : typeof SelfReferencingBase +>self : typeof SelfReferencingBase + +function mixin {}>(base: Base) { +>mixin : {}>(base: Base) => { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>args : any[] +>base : Base + + return class extends base { +>class extends base { static value = 1; value = 2; } : { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>base : {} + + static value = 1; +>value : number +>1 : 1 + + value = 2; +>value : number +>2 : 2 + + }; +} + +class Mixed extends mixin(NestedBase) {} +>Mixed : Mixed +>mixin(NestedBase) : mixin.(Anonymous class) & NestedBase +>mixin : {}>(base: Base) => { new (...args: any[]): (Anonymous class); value: number; prototype: mixin.(Anonymous class); } & Base +>NestedBase : typeof NestedBase + +const mixedStaticValue: number = Mixed.value; +>mixedStaticValue : number +>Mixed.value : number +>Mixed : typeof Mixed +>value : number + +const mixedInstanceValue: number = new Mixed().value; +>mixedInstanceValue : number +>new Mixed().value : number +>new Mixed() : Mixed +>Mixed : typeof Mixed +>value : number + +declare function makeBase(value: number): typeof NestedBase; +>makeBase : (value: number) => typeof NestedBase +>value : number +>NestedBase : typeof NestedBase + +class InvalidBaseArgument extends makeBase("invalid") {} +>InvalidBaseArgument : InvalidBaseArgument +>makeBase("invalid") : NestedBase +>makeBase : (value: number) => typeof NestedBase +>"invalid" : "invalid" + +const InvalidExpressionArgument = class extends makeBase("invalid") {}; +>InvalidExpressionArgument : typeof InvalidExpressionArgument +>class extends makeBase("invalid") {} : typeof InvalidExpressionArgument +>makeBase("invalid") : NestedBase +>makeBase : (value: number) => typeof NestedBase +>"invalid" : "invalid" + +declare function makeInvalidBase(value: number): number; +>makeInvalidBase : (value: number) => number +>value : number + +class InvalidConstructor extends makeInvalidBase("invalid") {} +>InvalidConstructor : InvalidConstructor +>makeInvalidBase("invalid") : number +>makeInvalidBase : (value: number) => number +>"invalid" : "invalid" + diff --git a/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.js b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.js new file mode 100644 index 0000000000000..774af8292c6a9 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/enumMemberTypeCacheConsistency.ts] //// + +//// [enumMemberTypeCacheConsistency.ts] +enum E { + A = 0, + B = E.A.valueOf(), + C = 1, +} + +const member: Extract = E.C; + +//// [enumMemberTypeCacheConsistency.js] +"use strict"; +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = E.A.valueOf()] = "B"; + E[E["C"] = 1] = "C"; +})(E || (E = {})); +const member = E.C; + + +//// [enumMemberTypeCacheConsistency.d.ts] +declare enum E { + A = 0, + B, + C = 1 +} +declare const member: Extract; diff --git a/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.symbols b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.symbols new file mode 100644 index 0000000000000..d527b2792f38e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.symbols @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/enumMemberTypeCacheConsistency.ts] //// + +=== enumMemberTypeCacheConsistency.ts === +enum E { +>E : Symbol(E, Decl(enumMemberTypeCacheConsistency.ts, 0, 0)) + + A = 0, +>A : Symbol(E.A, Decl(enumMemberTypeCacheConsistency.ts, 0, 8)) + + B = E.A.valueOf(), +>B : Symbol(E.B, Decl(enumMemberTypeCacheConsistency.ts, 1, 10)) +>E.A.valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --)) +>E.A : Symbol(E.A, Decl(enumMemberTypeCacheConsistency.ts, 0, 8)) +>E : Symbol(E, Decl(enumMemberTypeCacheConsistency.ts, 0, 0)) +>A : Symbol(E.A, Decl(enumMemberTypeCacheConsistency.ts, 0, 8)) +>valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --)) + + C = 1, +>C : Symbol(E.C, Decl(enumMemberTypeCacheConsistency.ts, 2, 22)) +} + +const member: Extract = E.C; +>member : Symbol(member, Decl(enumMemberTypeCacheConsistency.ts, 6, 5)) +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) +>E : Symbol(E, Decl(enumMemberTypeCacheConsistency.ts, 0, 0)) +>E.C : Symbol(E.C, Decl(enumMemberTypeCacheConsistency.ts, 2, 22)) +>E : Symbol(E, Decl(enumMemberTypeCacheConsistency.ts, 0, 0)) +>C : Symbol(E.C, Decl(enumMemberTypeCacheConsistency.ts, 2, 22)) + diff --git a/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.types b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.types new file mode 100644 index 0000000000000..118dbac02ec0b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/enumMemberTypeCacheConsistency.types @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/enumMemberTypeCacheConsistency.ts] //// + +=== enumMemberTypeCacheConsistency.ts === +enum E { +>E : E + + A = 0, +>A : E.A +>0 : 0 + + B = E.A.valueOf(), +>B : E.B +>E.A.valueOf() : number +>E.A.valueOf : () => number +>E.A : E.A +>E : typeof E +>A : E.A +>valueOf : () => number + + C = 1, +>C : E.C +>1 : 1 +} + +const member: Extract = E.C; +>member : E.C +>E.C : E.C +>E : typeof E +>C : E.C + diff --git a/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.errors.txt b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.errors.txt new file mode 100644 index 0000000000000..ada42d0527e20 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.errors.txt @@ -0,0 +1,17 @@ +getterCircularityDiagnostics.ts(4,9): error TS7023: 'options' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. + + +==== getterCircularityDiagnostics.ts (1 errors) ==== + declare const props: Options; + + class Container { + get options() { + ~~~~~~~ +!!! error TS7023: 'options' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. + return { container: this, ...props } as Options; + } + } + + interface Options { + container?: Container; + } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.js b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.js new file mode 100644 index 0000000000000..e7507ff16bec4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/getterCircularityDiagnostics.ts] //// + +//// [getterCircularityDiagnostics.ts] +declare const props: Options; + +class Container { + get options() { + return { container: this, ...props } as Options; + } +} + +interface Options { + container?: Container; +} + +//// [getterCircularityDiagnostics.js] +"use strict"; +class Container { + get options() { + return Object.assign({ container: this }, props); + } +} diff --git a/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.symbols b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.symbols new file mode 100644 index 0000000000000..7ef53202b8061 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.symbols @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/getterCircularityDiagnostics.ts] //// + +=== getterCircularityDiagnostics.ts === +declare const props: Options; +>props : Symbol(props, Decl(getterCircularityDiagnostics.ts, 0, 13)) +>Options : Symbol(Options, Decl(getterCircularityDiagnostics.ts, 6, 1)) + +class Container { +>Container : Symbol(Container, Decl(getterCircularityDiagnostics.ts, 0, 29)) + + get options() { +>options : Symbol(Container.options, Decl(getterCircularityDiagnostics.ts, 2, 17)) + + return { container: this, ...props } as Options; +>container : Symbol(container, Decl(getterCircularityDiagnostics.ts, 4, 16)) +>this : Symbol(Container, Decl(getterCircularityDiagnostics.ts, 0, 29)) +>props : Symbol(props, Decl(getterCircularityDiagnostics.ts, 0, 13)) +>Options : Symbol(Options, Decl(getterCircularityDiagnostics.ts, 6, 1)) + } +} + +interface Options { +>Options : Symbol(Options, Decl(getterCircularityDiagnostics.ts, 6, 1)) + + container?: Container; +>container : Symbol(Options.container, Decl(getterCircularityDiagnostics.ts, 8, 19)) +>Container : Symbol(Container, Decl(getterCircularityDiagnostics.ts, 0, 29)) +} diff --git a/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.types b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.types new file mode 100644 index 0000000000000..03f8b125b218d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/getterCircularityDiagnostics.types @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/getterCircularityDiagnostics.ts] //// + +=== getterCircularityDiagnostics.ts === +declare const props: Options; +>props : Options + +class Container { +>Container : Container + + get options() { +>options : any + + return { container: this, ...props } as Options; +>{ container: this, ...props } as Options : Options +>{ container: this, ...props } : { container: Container; } +>container : this +>this : this +>props : Options + } +} + +interface Options { + container?: Container; +>container : Container | undefined +} diff --git a/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.errors.txt b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.errors.txt new file mode 100644 index 0000000000000..bafe2d1546822 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.errors.txt @@ -0,0 +1,19 @@ +file.js(4,11): error TS7022: 'pixel' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +file.js(4,19): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ skip: any; }'. +file.js(5,24): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ skip: any; }'. + + +==== file.js (3 errors) ==== + /** @param {any} axis @param {any} value */ + function updateElements(axis, value) { + const properties = {}; + const pixel = properties[axis] = value; + ~~~~~ +!!! error TS7022: 'pixel' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ skip: any; }'. + const otherPixel = properties[axis] = value; + ~~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ skip: any; }'. + properties.skip = isNaN(pixel) || isNaN(otherPixel); + } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.js b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.js new file mode 100644 index 0000000000000..d660e1f2146fc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts] //// + +//// [file.js] +/** @param {any} axis @param {any} value */ +function updateElements(axis, value) { + const properties = {}; + const pixel = properties[axis] = value; + const otherPixel = properties[axis] = value; + properties.skip = isNaN(pixel) || isNaN(otherPixel); +} + +//// [file.js] +"use strict"; +/** @param {any} axis @param {any} value */ +function updateElements(axis, value) { + const properties = {}; + const pixel = properties[axis] = value; + const otherPixel = properties[axis] = value; + properties.skip = isNaN(pixel) || isNaN(otherPixel); +} diff --git a/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.symbols b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.symbols new file mode 100644 index 0000000000000..373963a684ab3 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.symbols @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts] //// + +=== file.js === +/** @param {any} axis @param {any} value */ +function updateElements(axis, value) { +>updateElements : Symbol(updateElements, Decl(file.js, 0, 0)) +>axis : Symbol(axis, Decl(file.js, 1, 24)) +>value : Symbol(value, Decl(file.js, 1, 29)) + + const properties = {}; +>properties : Symbol(properties, Decl(file.js, 2, 9)) + + const pixel = properties[axis] = value; +>pixel : Symbol(pixel, Decl(file.js, 3, 9)) +>properties : Symbol(properties, Decl(file.js, 2, 9)) +>axis : Symbol(axis, Decl(file.js, 1, 24)) +>value : Symbol(value, Decl(file.js, 1, 29)) + + const otherPixel = properties[axis] = value; +>otherPixel : Symbol(otherPixel, Decl(file.js, 4, 9)) +>properties : Symbol(properties, Decl(file.js, 2, 9)) +>axis : Symbol(axis, Decl(file.js, 1, 24)) +>value : Symbol(value, Decl(file.js, 1, 29)) + + properties.skip = isNaN(pixel) || isNaN(otherPixel); +>properties.skip : Symbol(skip, Decl(file.js, 4, 48)) +>properties : Symbol(properties, Decl(file.js, 2, 9)) +>skip : Symbol(skip, Decl(file.js, 4, 48)) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>pixel : Symbol(pixel, Decl(file.js, 3, 9)) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>otherPixel : Symbol(otherPixel, Decl(file.js, 4, 9)) +} diff --git a/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.types b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.types new file mode 100644 index 0000000000000..607a8ed056027 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.types @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts] //// + +=== file.js === +/** @param {any} axis @param {any} value */ +function updateElements(axis, value) { +>updateElements : (axis: any, value: any) => void +>axis : any +>value : any + + const properties = {}; +>properties : { skip: any; } +>{} : { skip: any; } + + const pixel = properties[axis] = value; +>pixel : any +>properties[axis] = value : any +>properties[axis] : any +>properties : { skip: any; } +>axis : any +>value : any + + const otherPixel = properties[axis] = value; +>otherPixel : any +>properties[axis] = value : any +>properties[axis] : any +>properties : { skip: any; } +>axis : any +>value : any + + properties.skip = isNaN(pixel) || isNaN(otherPixel); +>properties.skip = isNaN(pixel) || isNaN(otherPixel) : boolean +>properties.skip : any +>properties : { skip: any; } +>skip : any +>isNaN(pixel) || isNaN(otherPixel) : boolean +>isNaN(pixel) : boolean +>isNaN : (number: number) => boolean +>pixel : any +>isNaN(otherPixel) : boolean +>isNaN : (number: number) => boolean +>otherPixel : any +} diff --git a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.errors.txt b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.errors.txt index a1b033edf54ba..e5a8fd2f27de5 100644 --- a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.errors.txt @@ -1,15 +1,14 @@ -limitDeepInstantiations.ts(4,9): error TS5114: Instantiations of type 'Foo' appear infinitely circular. -limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'. +limitDeepInstantiations.ts(7,13): error TS5114: Instantiations of type 'BuildTuple' appear infinitely circular. -==== limitDeepInstantiations.ts (2 errors) ==== - // Repro from #14837 +==== limitDeepInstantiations.ts (1 errors) ==== + type BuildTuple = + Elements["length"] extends Length ? [] : [unknown, ...BuildTuple]; - type Foo = { "true": Foo> }[T]; - let f1: Foo<"true", {}>; - ~~~~~~~~~~~~~~~ -!!! error TS5114: Instantiations of type 'Foo' appear infinitely circular. - let f2: Foo<"false", {}>; - ~~~~~~~ -!!! error TS2344: Type '"false"' does not satisfy the constraint '"true"'. + declare const shallow: BuildTuple<8>; + const shallowLength: 8 = shallow.length; + + type Deep = BuildTuple<200>; + ~~~~~~~~~~~~~~~ +!!! error TS5114: Instantiations of type 'BuildTuple' appear infinitely circular. \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.js b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.js index 5c149c0177558..cd62b2e02af43 100644 --- a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.js +++ b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.js @@ -1,15 +1,15 @@ //// [tests/cases/compiler/limitDeepInstantiations.ts] //// //// [limitDeepInstantiations.ts] -// Repro from #14837 +type BuildTuple = + Elements["length"] extends Length ? [] : [unknown, ...BuildTuple]; -type Foo = { "true": Foo> }[T]; -let f1: Foo<"true", {}>; -let f2: Foo<"false", {}>; +declare const shallow: BuildTuple<8>; +const shallowLength: 8 = shallow.length; + +type Deep = BuildTuple<200>; //// [limitDeepInstantiations.js] "use strict"; -// Repro from #14837 -let f1; -let f2; +const shallowLength = shallow.length; diff --git a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.symbols b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.symbols index 73413334b6b82..f5d993454616f 100644 --- a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.symbols +++ b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.symbols @@ -1,25 +1,29 @@ //// [tests/cases/compiler/limitDeepInstantiations.ts] //// === limitDeepInstantiations.ts === -// Repro from #14837 +type BuildTuple = +>BuildTuple : Symbol(BuildTuple, Decl(limitDeepInstantiations.ts, 0, 0)) +>Length : Symbol(Length, Decl(limitDeepInstantiations.ts, 0, 16)) +>Elements : Symbol(Elements, Decl(limitDeepInstantiations.ts, 0, 38)) -type Foo = { "true": Foo> }[T]; ->Foo : Symbol(Foo, Decl(limitDeepInstantiations.ts, 0, 0)) ->T : Symbol(T, Decl(limitDeepInstantiations.ts, 2, 9)) ->B : Symbol(B, Decl(limitDeepInstantiations.ts, 2, 26)) ->"true" : Symbol("true", Decl(limitDeepInstantiations.ts, 2, 33)) ->Foo : Symbol(Foo, Decl(limitDeepInstantiations.ts, 0, 0)) ->T : Symbol(T, Decl(limitDeepInstantiations.ts, 2, 9)) ->Foo : Symbol(Foo, Decl(limitDeepInstantiations.ts, 0, 0)) ->T : Symbol(T, Decl(limitDeepInstantiations.ts, 2, 9)) ->B : Symbol(B, Decl(limitDeepInstantiations.ts, 2, 26)) ->T : Symbol(T, Decl(limitDeepInstantiations.ts, 2, 9)) + Elements["length"] extends Length ? [] : [unknown, ...BuildTuple]; +>Elements : Symbol(Elements, Decl(limitDeepInstantiations.ts, 0, 38)) +>Length : Symbol(Length, Decl(limitDeepInstantiations.ts, 0, 16)) +>BuildTuple : Symbol(BuildTuple, Decl(limitDeepInstantiations.ts, 0, 0)) +>Length : Symbol(Length, Decl(limitDeepInstantiations.ts, 0, 16)) +>Elements : Symbol(Elements, Decl(limitDeepInstantiations.ts, 0, 38)) -let f1: Foo<"true", {}>; ->f1 : Symbol(f1, Decl(limitDeepInstantiations.ts, 3, 3)) ->Foo : Symbol(Foo, Decl(limitDeepInstantiations.ts, 0, 0)) +declare const shallow: BuildTuple<8>; +>shallow : Symbol(shallow, Decl(limitDeepInstantiations.ts, 3, 13)) +>BuildTuple : Symbol(BuildTuple, Decl(limitDeepInstantiations.ts, 0, 0)) -let f2: Foo<"false", {}>; ->f2 : Symbol(f2, Decl(limitDeepInstantiations.ts, 4, 3)) ->Foo : Symbol(Foo, Decl(limitDeepInstantiations.ts, 0, 0)) +const shallowLength: 8 = shallow.length; +>shallowLength : Symbol(shallowLength, Decl(limitDeepInstantiations.ts, 4, 5)) +>shallow.length : Symbol(length) +>shallow : Symbol(shallow, Decl(limitDeepInstantiations.ts, 3, 13)) +>length : Symbol(length) + +type Deep = BuildTuple<200>; +>Deep : Symbol(Deep, Decl(limitDeepInstantiations.ts, 4, 40)) +>BuildTuple : Symbol(BuildTuple, Decl(limitDeepInstantiations.ts, 0, 0)) diff --git a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.types b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.types index 520205007876c..a8bcb7c4939e3 100644 --- a/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.types +++ b/tsc/testdata/baselines/reference/compiler/limitDeepInstantiations.types @@ -1,15 +1,20 @@ //// [tests/cases/compiler/limitDeepInstantiations.ts] //// === limitDeepInstantiations.ts === -// Repro from #14837 +type BuildTuple = +>BuildTuple : BuildTuple -type Foo = { "true": Foo> }[T]; ->Foo : Foo ->"true" : Foo> + Elements["length"] extends Length ? [] : [unknown, ...BuildTuple]; -let f1: Foo<"true", {}>; ->f1 : any +declare const shallow: BuildTuple<8>; +>shallow : [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown] -let f2: Foo<"false", {}>; ->f2 : unknown +const shallowLength: 8 = shallow.length; +>shallowLength : 8 +>shallow.length : 8 +>shallow : [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown] +>length : 8 + +type Deep = BuildTuple<200>; +>Deep : [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, ...any[]] diff --git a/tsc/testdata/baselines/reference/compiler/noUsedBeforeDefinedErrorInTypeContext.types b/tsc/testdata/baselines/reference/compiler/noUsedBeforeDefinedErrorInTypeContext.types index 9e1af3aba2e96..66a56357cadaa 100644 --- a/tsc/testdata/baselines/reference/compiler/noUsedBeforeDefinedErrorInTypeContext.types +++ b/tsc/testdata/baselines/reference/compiler/noUsedBeforeDefinedErrorInTypeContext.types @@ -9,14 +9,14 @@ interface IThing { } var foo = { ->foo : any +>foo : error >{ one: {} as IThing,} : { one: IThing; } one: {} as IThing, >one : IThing >{} as IThing : IThing >{} : {} ->foo : any +>foo : error } let baz = { @@ -27,28 +27,28 @@ let baz = { >two : IThing >{} as IThing : IThing >{} : {} ->bar : any +>bar : error } let bar = { ->bar : any +>bar : error >{ three: {} as IThing,} : { three: IThing; } three: {} as IThing, >three : IThing >{} as IThing : IThing >{} : {} ->bar : any +>bar : error } const qwe = { ->qwe : any +>qwe : error >{ four: {} as IThing,} : { four: IThing; } four: {} as IThing, >four : IThing >{} as IThing : IThing >{} : {} ->qwe : any +>qwe : error } diff --git a/tsc/testdata/baselines/reference/compiler/recur1.types b/tsc/testdata/baselines/reference/compiler/recur1.types index 9f95e6bafec8c..f3289e90bc4e3 100644 --- a/tsc/testdata/baselines/reference/compiler/recur1.types +++ b/tsc/testdata/baselines/reference/compiler/recur1.types @@ -16,15 +16,15 @@ salt.pepper = function() {} >function() {} : () => void var cobalt = new cobalt.pitch(); ->cobalt : any ->new cobalt.pitch() : any ->cobalt.pitch : any +>cobalt : error +>new cobalt.pitch() : error +>cobalt.pitch : error >cobalt : any >pitch : any cobalt.pitch = function() {} >cobalt.pitch = function() {} : () => void ->cobalt.pitch : any +>cobalt.pitch : error >cobalt : any >pitch : any >function() {} : () => void diff --git a/tsc/testdata/baselines/reference/compiler/recursiveExportAssignmentAndFindAliasedType7.types b/tsc/testdata/baselines/reference/compiler/recursiveExportAssignmentAndFindAliasedType7.types index 5ae57520bbc0f..47a76fcaffc1f 100644 --- a/tsc/testdata/baselines/reference/compiler/recursiveExportAssignmentAndFindAliasedType7.types +++ b/tsc/testdata/baselines/reference/compiler/recursiveExportAssignmentAndFindAliasedType7.types @@ -15,8 +15,8 @@ import self = require("./recursiveExportAssignmentAndFindAliasedType7_moduleD"); >self : any var selfVar = self; ->selfVar : any ->self : any +>selfVar : error +>self : error export = selfVar; >selfVar : any diff --git a/tsc/testdata/baselines/reference/compiler/recursiveGetterAccess.types b/tsc/testdata/baselines/reference/compiler/recursiveGetterAccess.types index f19e896cfda33..bf04d7628347a 100644 --- a/tsc/testdata/baselines/reference/compiler/recursiveGetterAccess.types +++ b/tsc/testdata/baselines/reference/compiler/recursiveGetterAccess.types @@ -5,8 +5,8 @@ class MyClass { >MyClass : MyClass get testProp() { return this.testProp; } ->testProp : any ->this.testProp : any +>testProp : error +>this.testProp : error >this : this >testProp : any } diff --git a/tsc/testdata/baselines/reference/compiler/recursiveProperties(target=es2015).types b/tsc/testdata/baselines/reference/compiler/recursiveProperties(target=es2015).types index ed0b35b15e4e2..cc34edbb80436 100644 --- a/tsc/testdata/baselines/reference/compiler/recursiveProperties(target=es2015).types +++ b/tsc/testdata/baselines/reference/compiler/recursiveProperties(target=es2015).types @@ -5,8 +5,8 @@ class A { >A : A get testProp() { return this.testProp; } ->testProp : any ->this.testProp : any +>testProp : error +>this.testProp : error >this : this >testProp : any } diff --git a/tsc/testdata/baselines/reference/conformance/assignmentCompatWithObjectMembers.types b/tsc/testdata/baselines/reference/conformance/assignmentCompatWithObjectMembers.types index 39926639639aa..87ed4300af21b 100644 --- a/tsc/testdata/baselines/reference/conformance/assignmentCompatWithObjectMembers.types +++ b/tsc/testdata/baselines/reference/conformance/assignmentCompatWithObjectMembers.types @@ -189,16 +189,16 @@ namespace ObjectTypes { >b : { foo: typeof b; } var a2 = { foo: a2 }; ->a2 : any +>a2 : error >{ foo: a2 } : { foo: any; } ->foo : any ->a2 : any +>foo : error +>a2 : error var b2 = { foo: b2 }; ->b2 : any +>b2 : error >{ foo: b2 } : { foo: any; } ->foo : any ->b2 : any +>foo : error +>b2 : error s = t; >s = t : T @@ -216,9 +216,9 @@ namespace ObjectTypes { >s2 : S2 s = a2; ->s = a2 : any +>s = a2 : error >s : S ->a2 : any +>a2 : error s2 = t2; >s2 = t2 : T2 @@ -241,9 +241,9 @@ namespace ObjectTypes { >b : { foo: typeof b; } s2 = a2; ->s2 = a2 : any +>s2 = a2 : error >s2 : S2 ->a2 : any +>a2 : error a = b; >a = b : { foo: typeof b; } @@ -266,33 +266,33 @@ namespace ObjectTypes { >s2 : S2 a = a2; ->a = a2 : any +>a = a2 : error >a : { foo: typeof a; } ->a2 : any +>a2 : error a2 = b2; ->a2 = b2 : any ->a2 : any ->b2 : any +>a2 = b2 : error +>a2 : error +>b2 : error b2 = a2; ->b2 = a2 : any ->b2 : any ->a2 : any +>b2 = a2 : error +>b2 : error +>a2 : error a2 = b; >a2 = b : { foo: typeof b; } ->a2 : any +>a2 : error >b : { foo: typeof b; } a2 = t2; >a2 = t2 : T2 ->a2 : any +>a2 : error >t2 : T2 a2 = t; >a2 = t : T ->a2 : any +>a2 : error >t : T } diff --git a/tsc/testdata/baselines/reference/conformance/binderUninitializedModuleExportsAssignment.types b/tsc/testdata/baselines/reference/conformance/binderUninitializedModuleExportsAssignment.types index e505b3f68544c..964101e695f63 100644 --- a/tsc/testdata/baselines/reference/conformance/binderUninitializedModuleExportsAssignment.types +++ b/tsc/testdata/baselines/reference/conformance/binderUninitializedModuleExportsAssignment.types @@ -2,17 +2,17 @@ === loop.js === var loop1 = loop2; ->loop1 : any ->loop2 : any +>loop1 : error +>loop2 : error var loop2 = loop1; ->loop2 : any ->loop1 : any +>loop2 : error +>loop1 : error module.exports = loop2; ->module.exports = loop2 : any ->module.exports : any +>module.exports = loop2 : error +>module.exports : error >module : { exports: any; } >exports : any ->loop2 : any +>loop2 : error diff --git a/tsc/testdata/baselines/reference/conformance/circularIndexedAccessErrors.errors.txt b/tsc/testdata/baselines/reference/conformance/circularIndexedAccessErrors.errors.txt index fb39c766dfad9..a28d9327541e4 100644 --- a/tsc/testdata/baselines/reference/conformance/circularIndexedAccessErrors.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/circularIndexedAccessErrors.errors.txt @@ -1,5 +1,5 @@ circularIndexedAccessErrors.ts(2,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. -circularIndexedAccessErrors.ts(11,11): error TS2589: Type instantiation is excessively deep and possibly infinite. +circularIndexedAccessErrors.ts(6,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. circularIndexedAccessErrors.ts(18,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. circularIndexedAccessErrors.ts(22,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. circularIndexedAccessErrors.ts(26,5): error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor. @@ -18,13 +18,13 @@ circularIndexedAccessErrors.ts(37,30): error TS2536: Type '"hello"' cannot be us type T2 = { x: T2[K]; // Error + ~ +!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation. y: number; } declare let x2: T2<"x">; let x2x = x2.x; - ~~~~ -!!! error TS2589: Type instantiation is excessively deep and possibly infinite. interface T3> { x: T["x"]; diff --git a/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES5.types b/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES5.types index ede3d87119238..0353951942c22 100644 --- a/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } }; >{ b5: { b52 } } : { b5: { b52: any; }; } >b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any +>b52 : error // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature diff --git a/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES6.types b/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES6.types index 73c766ede6ea0..4fdeec2ff34da 100644 --- a/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tsc/testdata/baselines/reference/conformance/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } }; >{ b5: { b52 } } : { b5: { b52: any; }; } >b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any +>b52 : error // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature diff --git a/tsc/testdata/baselines/reference/conformance/exportAssignmentCircularModules.types b/tsc/testdata/baselines/reference/conformance/exportAssignmentCircularModules.types index faa4bd3fbf786..a8b18a15d9847 100644 --- a/tsc/testdata/baselines/reference/conformance/exportAssignmentCircularModules.types +++ b/tsc/testdata/baselines/reference/conformance/exportAssignmentCircularModules.types @@ -8,8 +8,8 @@ namespace Foo { >Foo : typeof Foo export var x = foo0.x; ->x : any ->foo0.x : any +>x : error +>foo0.x : error >foo0 : typeof foo0 >x : any } @@ -24,8 +24,8 @@ namespace Foo { >Foo : typeof Foo export var x = foo1.x; ->x : any ->foo1.x : any +>x : error +>foo1.x : error >foo1 : typeof foo1 >x : any } @@ -40,8 +40,8 @@ namespace Foo { >Foo : typeof Foo export var x = foo2.x; ->x : any ->foo2.x : any +>x : error +>foo2.x : error >foo2 : typeof foo2 >x : any } diff --git a/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandProperties(target=es2015).types b/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandProperties(target=es2015).types index d99e68712b9a3..806cb60d3e48e 100644 --- a/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandProperties(target=es2015).types +++ b/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandProperties(target=es2015).types @@ -24,7 +24,7 @@ var x2 = { } var x3 = { ->x3 : any +>x3 : error >{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, @@ -41,11 +41,11 @@ var x3 = { >d : () => void x3, ->x3 : any +>x3 : error parent: x3 ->parent : any ->x3 : any +>parent : error +>x3 : error }; diff --git a/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandPropertiesES6.types b/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandPropertiesES6.types index 2097a6554b049..13cd431d35f9a 100644 --- a/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandPropertiesES6.types +++ b/tsc/testdata/baselines/reference/conformance/objectLiteralShorthandPropertiesES6.types @@ -24,7 +24,7 @@ var x2 = { } var x3 = { ->x3 : any +>x3 : error >{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, @@ -41,11 +41,11 @@ var x3 = { >d : () => void x3, ->x3 : any +>x3 : error parent: x3 ->parent : any ->x3 : any +>parent : error +>x3 : error }; diff --git a/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement18(target=es2015).types b/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement18(target=es2015).types index 029dae57b1f38..9fabaca3a564e 100644 --- a/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement18(target=es2015).types +++ b/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement18(target=es2015).types @@ -2,6 +2,6 @@ === parserES5ForOfStatement18.ts === for (var of of of) { } ->of : any ->of : any +>of : error +>of : error diff --git a/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement19(target=es2015).types b/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement19(target=es2015).types index b46f470c960a6..d44ce8be4f9b5 100644 --- a/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement19(target=es2015).types +++ b/tsc/testdata/baselines/reference/conformance/parserES5ForOfStatement19(target=es2015).types @@ -2,6 +2,6 @@ === parserES5ForOfStatement19.ts === for (var of in of) { } ->of : any ->of : any +>of : error +>of : error diff --git a/tsc/testdata/baselines/reference/conformance/parserForOfStatement18.types b/tsc/testdata/baselines/reference/conformance/parserForOfStatement18.types index d1313c31dfeab..fa9768abc1cab 100644 --- a/tsc/testdata/baselines/reference/conformance/parserForOfStatement18.types +++ b/tsc/testdata/baselines/reference/conformance/parserForOfStatement18.types @@ -2,6 +2,6 @@ === parserForOfStatement18.ts === for (var of of of) { } ->of : any ->of : any +>of : error +>of : error diff --git a/tsc/testdata/baselines/reference/conformance/parserForOfStatement19.types b/tsc/testdata/baselines/reference/conformance/parserForOfStatement19.types index 94d5215fb59a4..3c9b9f27c1d0f 100644 --- a/tsc/testdata/baselines/reference/conformance/parserForOfStatement19.types +++ b/tsc/testdata/baselines/reference/conformance/parserForOfStatement19.types @@ -2,6 +2,6 @@ === parserForOfStatement19.ts === for (var of in of) { } ->of : any ->of : any +>of : error +>of : error diff --git a/tsc/testdata/baselines/reference/conformance/recursiveInitializer.types b/tsc/testdata/baselines/reference/conformance/recursiveInitializer.types index b5ad6a91dde18..2dbe70dcaf02a 100644 --- a/tsc/testdata/baselines/reference/conformance/recursiveInitializer.types +++ b/tsc/testdata/baselines/reference/conformance/recursiveInitializer.types @@ -3,9 +3,9 @@ === recursiveInitializer.ts === // number unless otherwise specified var n1 = n1++; ->n1 : any +>n1 : error >n1++ : number ->n1 : any +>n1 : error var n2: number = n2 + n2; >n2 : number @@ -14,23 +14,23 @@ var n2: number = n2 + n2; >n2 : number var n3 /* any */ = n3 + n3; ->n3 : any ->n3 + n3 : any ->n3 : any ->n3 : any +>n3 : error +>n3 + n3 : error +>n3 : error +>n3 : error // string unless otherwise specified var s1 = s1 + ''; ->s1 : any +>s1 : error >s1 + '' : string ->s1 : any +>s1 : error >'' : "" var s2 /* any */ = s2 + s2; ->s2 : any ->s2 + s2 : any ->s2 : any ->s2 : any +>s2 : error +>s2 + s2 : error +>s2 : error +>s2 : error var s3 : string = s3 + s3; >s3 : string @@ -39,37 +39,37 @@ var s3 : string = s3 + s3; >s3 : string var s4 = '' + s4; ->s4 : any +>s4 : error >'' + s4 : string >'' : "" ->s4 : any +>s4 : error // boolean unless otherwise specified var b1 = !b1; ->b1 : any +>b1 : error >!b1 : boolean ->b1 : any +>b1 : error var b2 = !!b2; ->b2 : any +>b2 : error >!!b2 : boolean >!b2 : boolean ->b2 : any +>b2 : error var b3 = !b3 || b3; // expected boolean here. actually 'any' ->b3 : any ->!b3 || b3 : any +>b3 : error +>!b3 || b3 : error >!b3 : boolean ->b3 : any ->b3 : any +>b3 : error +>b3 : error var b4 = (!b4) && b4; // expected boolean here. actually 'any' ->b4 : any ->(!b4) && b4 : any +>b4 : error +>(!b4) && b4 : error >(!b4) : boolean >!b4 : boolean ->b4 : any ->b4 : any +>b4 : error +>b4 : error // (x:string) => any var f = (x: string) => f(x); diff --git a/tsc/testdata/baselines/reference/conformance/templateStringInYieldKeyword.types b/tsc/testdata/baselines/reference/conformance/templateStringInYieldKeyword.types index e504aaaf5a7e9..73d1a3c7b67f9 100644 --- a/tsc/testdata/baselines/reference/conformance/templateStringInYieldKeyword.types +++ b/tsc/testdata/baselines/reference/conformance/templateStringInYieldKeyword.types @@ -6,9 +6,9 @@ function* gen() { // Once this is supported, the inner expression does not need to be parenthesized. var x = yield `abc${ x }def`; ->x : any +>x : error >yield `abc${ x }def` : any >`abc${ x }def` : string ->x : any +>x : error } diff --git a/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8.types b/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8.types index 51f9c0f3097f5..894461812ca13 100644 --- a/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8.types +++ b/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8.types @@ -2,25 +2,25 @@ === a.js === var my = my || {}; ->my : any ->my || {} : any ->my : any +>my : error +>my || {} : error +>my : error >{} : {} my.app = my.app || {}; ->my.app = my.app || {} : any ->my.app : any +>my.app = my.app || {} : error +>my.app : error >my : any >app : any ->my.app || {} : any ->my.app : any +>my.app || {} : error +>my.app : error >my : any >app : any >{} : {} my.app.Application = (function () { >my.app.Application = (function () {var Application = function () { //...};return Application;})() : () => void ->my.app.Application : any +>my.app.Application : error >my.app : any >my : any >app : any @@ -40,8 +40,8 @@ return Application; })(); my.app.Application() ->my.app.Application() : any ->my.app.Application : any +>my.app.Application() : error +>my.app.Application : error >my.app : any >my : any >app : any @@ -49,27 +49,27 @@ my.app.Application() === b.js === var min = window.min || {}; ->min : any ->window.min || {} : any ->window.min : any +>min : error +>window.min || {} : error +>window.min : error >window : Window & typeof globalThis >min : any >{} : {} min.app = min.app || {}; ->min.app = min.app || {} : any ->min.app : any +>min.app = min.app || {} : error +>min.app : error >min : any >app : any ->min.app || {} : any ->min.app : any +>min.app || {} : error +>min.app : error >min : any >app : any >{} : {} min.app.Application = (function () { >min.app.Application = (function () {var Application = function () { //...};return Application;})() : () => void ->min.app.Application : any +>min.app.Application : error >min.app : any >min : any >app : any @@ -89,8 +89,8 @@ return Application; })(); min.app.Application() ->min.app.Application() : any ->min.app.Application : any +>min.app.Application() : error +>min.app.Application : error >min.app : any >min : any >app : any diff --git a/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8_1.types b/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8_1.types index 6fb148ff1352b..e30d4153f3bdb 100644 --- a/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8_1.types +++ b/tsc/testdata/baselines/reference/conformance/typeFromPropertyAssignment8_1.types @@ -2,25 +2,25 @@ === a.js === var my = my ?? {}; ->my : any ->my ?? {} : any ->my : any +>my : error +>my ?? {} : error +>my : error >{} : {} my.app = my.app ?? {}; ->my.app = my.app ?? {} : any ->my.app : any +>my.app = my.app ?? {} : error +>my.app : error >my : any >app : any ->my.app ?? {} : any ->my.app : any +>my.app ?? {} : error +>my.app : error >my : any >app : any >{} : {} my.app.Application = (function () { >my.app.Application = (function () {var Application = function () { //...};return Application;})() : () => void ->my.app.Application : any +>my.app.Application : error >my.app : any >my : any >app : any @@ -40,8 +40,8 @@ return Application; })(); my.app.Application() ->my.app.Application() : any ->my.app.Application : any +>my.app.Application() : error +>my.app.Application : error >my.app : any >my : any >app : any @@ -49,27 +49,27 @@ my.app.Application() === b.js === var min = window.min ?? {}; ->min : any ->window.min ?? {} : any ->window.min : any +>min : error +>window.min ?? {} : error +>window.min : error >window : Window & typeof globalThis >min : any >{} : {} min.app = min.app ?? {}; ->min.app = min.app ?? {} : any ->min.app : any +>min.app = min.app ?? {} : error +>min.app : error >min : any >app : any ->min.app ?? {} : any ->min.app : any +>min.app ?? {} : error +>min.app : error >min : any >app : any >{} : {} min.app.Application = (function () { >min.app.Application = (function () {var Application = function () { //...};return Application;})() : () => void ->min.app.Application : any +>min.app.Application : error >min.app : any >min : any >app : any @@ -89,8 +89,8 @@ return Application; })(); min.app.Application() ->min.app.Application() : any ->min.app.Application : any +>min.app.Application() : error +>min.app.Application : error >min.app : any >min : any >app : any diff --git a/tsc/testdata/baselines/reference/conformance/witness.errors.txt b/tsc/testdata/baselines/reference/conformance/witness.errors.txt index 937e545c4db4d..0728971cff298 100644 --- a/tsc/testdata/baselines/reference/conformance/witness.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/witness.errors.txt @@ -1,27 +1,23 @@ -witness.ts(4,21): error TS2372: Parameter 'pInit' cannot reference itself. -witness.ts(8,14): error TS2729: Property 'x' is used before its initialization. -witness.ts(20,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'never'. -witness.ts(28,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(29,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'co1' must be of type 'any', but here has type 'number'. -witness.ts(30,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(30,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(32,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(32,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(32,12): error TS2695: Left side of comma operator is unused and has no side effects. -witness.ts(33,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'co3' must be of type 'any', but here has type 'number'. -witness.ts(37,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as1' must be of type 'any', but here has type 'number'. -witness.ts(39,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as2' must be of type 'any', but here has type 'number'. -witness.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'cnd1' must be of type 'any', but here has type 'number'. -witness.ts(50,11): error TS2873: This kind of expression is always falsy. -witness.ts(57,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. -witness.ts(58,12): error TS2873: This kind of expression is always falsy. -witness.ts(68,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'fnCallResult' must be of type 'never', but here has type 'any'. -witness.ts(110,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'propAcc1' must be of type 'any', but here has type '{ m: any; }'. -witness.ts(121,14): error TS2729: Property 'n' is used before its initialization. -witness.ts(128,19): error TS2729: Property 'q' is used before its initialization. +witness.ts(7,21): error TS2372: Parameter 'pInit' cannot reference itself. +witness.ts(11,14): error TS2729: Property 'x' is used before its initialization. +witness.ts(23,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'never'. +witness.ts(31,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(33,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(33,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(35,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(35,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(35,12): error TS2695: Left side of comma operator is unused and has no side effects. +witness.ts(53,11): error TS2873: This kind of expression is always falsy. +witness.ts(61,12): error TS2873: This kind of expression is always falsy. +witness.ts(71,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'fnCallResult' must be of type 'never', but here has type 'any'. +witness.ts(124,14): error TS2729: Property 'n' is used before its initialization. +witness.ts(131,19): error TS2729: Property 'q' is used before its initialization. -==== witness.ts (21 errors) ==== +==== witness.ts (14 errors) ==== + type IsAny = 0 extends (1 & Type) ? true : false; + type Assert = Condition; + // Initializers var varInit = varInit; // any var pInit: any; @@ -34,7 +30,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization x = this.x; ~ !!! error TS2729: Property 'x' is used before its initialization. -!!! related TS2728 witness.ts:8:5: 'x' is declared here. +!!! related TS2728 witness.ts:11:5: 'x' is declared here. fn() { var y = this.x; var y: any; @@ -49,7 +45,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var a = fnReturn1(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'never'. -!!! related TS6203 witness.ts:19:5: 'a' was also declared here. +!!! related TS6203 witness.ts:22:5: 'a' was also declared here. function fnReturn2() { return fnReturn2; @@ -60,10 +56,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var co1 = (co1, 3); ~~~ !!! error TS2695: Left side of comma operator is unused and has no side effects. - var co1: number; - ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'co1' must be of type 'any', but here has type 'number'. -!!! related TS6203 witness.ts:28:5: 'co1' was also declared here. + type CommaInference = Assert>; var co2 = (3, 4, co2); ~ !!! error TS2695: Left side of comma operator is unused and has no side effects. @@ -77,29 +70,17 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization !!! error TS2695: Left side of comma operator is unused and has no side effects. ~~~~~~~~~~~~~ !!! error TS2695: Left side of comma operator is unused and has no side effects. - var co3: number; - ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'co3' must be of type 'any', but here has type 'number'. -!!! related TS6203 witness.ts:32:5: 'co3' was also declared here. + type NestedCommaInference = Assert>; // Assignment var as1 = (as1 = 2); - var as1: number; - ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'as1' must be of type 'any', but here has type 'number'. -!!! related TS6203 witness.ts:36:5: 'as1' was also declared here. + type AssignmentInference = Assert>; var as2 = (as2 = as2 = 2); - var as2: number; - ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'as2' must be of type 'any', but here has type 'number'. -!!! related TS6203 witness.ts:38:5: 'as2' was also declared here. + type NestedAssignmentInference = Assert>; // Conditional var cnd1 = cnd1 ? 0 : 1; - var cnd1: number; - ~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'cnd1' must be of type 'any', but here has type 'number'. -!!! related TS6203 witness.ts:42:5: 'cnd1' was also declared here. + type ConditionalInference = Assert>; var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; var cnd2: string; @@ -115,10 +96,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization // && var and1 = and1 && ''; - var and1: string; - ~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. -!!! related TS6203 witness.ts:56:5: 'and1' was also declared here. + type LogicalAndInference = Assert>; var and2 = '' && and2; ~~ !!! error TS2873: This kind of expression is always falsy. @@ -134,7 +112,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var fnCallResult: any; ~~~~~~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'fnCallResult' must be of type 'never', but here has type 'any'. -!!! related TS6203 witness.ts:67:5: 'fnCallResult' was also declared here. +!!! related TS6203 witness.ts:70:5: 'fnCallResult' was also declared here. // Call argument function fnArg1(x: typeof fnArg1, y: number) { @@ -176,10 +154,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var propAcc1 = { m: propAcc1.m }; - var propAcc1: { m: any; } - ~~~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'propAcc1' must be of type 'any', but here has type '{ m: any; }'. -!!! related TS6203 witness.ts:107:5: 'propAcc1' was also declared here. + type PropertyAccessInference = Assert>; // Property access of namespace member namespace M2 { @@ -193,7 +168,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization n = this.n; // n: any ~ !!! error TS2729: Property 'n' is used before its initialization. -!!! related TS2728 witness.ts:121:5: 'n' is declared here. +!!! related TS2728 witness.ts:124:5: 'n' is declared here. } var c2inst = new C2().n; var c2inst: any; @@ -203,7 +178,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization static q = C3.q; ~ !!! error TS2729: Property 'q' is used before its initialization. -!!! related TS2728 witness.ts:128:12: 'q' is declared here. +!!! related TS2728 witness.ts:131:12: 'q' is declared here. } var qq = C3.q; var qq: any; diff --git a/tsc/testdata/baselines/reference/conformance/witness.js b/tsc/testdata/baselines/reference/conformance/witness.js index 939a0b95422f2..0b7eb560f0df8 100644 --- a/tsc/testdata/baselines/reference/conformance/witness.js +++ b/tsc/testdata/baselines/reference/conformance/witness.js @@ -1,6 +1,9 @@ //// [tests/cases/conformance/types/witness/witness.ts] //// //// [witness.ts] +type IsAny = 0 extends (1 & Type) ? true : false; +type Assert = Condition; + // Initializers var varInit = varInit; // any var pInit: any; @@ -29,21 +32,21 @@ var fnr2: () => any = fnReturn2(); // Comma var co1 = (co1, 3); -var co1: number; +type CommaInference = Assert>; var co2 = (3, 4, co2); var co2: any; var co3 = (co1, co2, co3, co1); -var co3: number; +type NestedCommaInference = Assert>; // Assignment var as1 = (as1 = 2); -var as1: number; +type AssignmentInference = Assert>; var as2 = (as2 = as2 = 2); -var as2: number; +type NestedAssignmentInference = Assert>; // Conditional var cnd1 = cnd1 ? 0 : 1; -var cnd1: number; +type ConditionalInference = Assert>; var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; var cnd2: string; @@ -57,7 +60,7 @@ var or3: any; // && var and1 = and1 && ''; -var and1: string; +type LogicalAndInference = Assert>; var and2 = '' && and2; var and2: any; var and3 = and3 && and3; @@ -110,7 +113,7 @@ var fn5r = fn5(); // fn5r: should be 'any', but is 'number' var propAcc1 = { m: propAcc1.m }; -var propAcc1: { m: any; } +type PropertyAccessInference = Assert>; // Property access of namespace member namespace M2 { @@ -167,19 +170,14 @@ function fnReturn2() { var fnr2 = fnReturn2(); // Comma var co1 = (co1, 3); -var co1; var co2 = (3, 4, co2); var co2; var co3 = (co1, co2, co3, co1); -var co3; // Assignment var as1 = (as1 = 2); -var as1; var as2 = (as2 = as2 = 2); -var as2; // Conditional var cnd1 = cnd1 ? 0 : 1; -var cnd1; var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; var cnd2; // || @@ -191,7 +189,6 @@ var or3 = or3 || or3; var or3; // && var and1 = and1 && ''; -var and1; var and2 = '' && and2; var and2; var and3 = and3 && and3; @@ -235,7 +232,6 @@ var fn5r = fn5(); // fn5r: should be 'any', but is 'number' var propAcc1 = { m: propAcc1.m }; -var propAcc1; // Property access of namespace member var M2; (function (M2) { diff --git a/tsc/testdata/baselines/reference/conformance/witness.symbols b/tsc/testdata/baselines/reference/conformance/witness.symbols index 5c1a03126efa3..4f6a0bd3e58a4 100644 --- a/tsc/testdata/baselines/reference/conformance/witness.symbols +++ b/tsc/testdata/baselines/reference/conformance/witness.symbols @@ -1,352 +1,382 @@ //// [tests/cases/conformance/types/witness/witness.ts] //// === witness.ts === +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>Type : Symbol(Type, Decl(witness.ts, 0, 11)) +>Type : Symbol(Type, Decl(witness.ts, 0, 11)) + +type Assert = Condition; +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>Condition : Symbol(Condition, Decl(witness.ts, 1, 12)) +>Condition : Symbol(Condition, Decl(witness.ts, 1, 12)) + // Initializers var varInit = varInit; // any ->varInit : Symbol(varInit, Decl(witness.ts, 1, 3)) ->varInit : Symbol(varInit, Decl(witness.ts, 1, 3)) +>varInit : Symbol(varInit, Decl(witness.ts, 4, 3)) +>varInit : Symbol(varInit, Decl(witness.ts, 4, 3)) var pInit: any; ->pInit : Symbol(pInit, Decl(witness.ts, 2, 3)) +>pInit : Symbol(pInit, Decl(witness.ts, 5, 3)) function fn(pInit = pInit) { ->fn : Symbol(fn, Decl(witness.ts, 2, 15)) ->pInit : Symbol(pInit, Decl(witness.ts, 3, 12), Decl(witness.ts, 4, 7)) ->pInit : Symbol(pInit, Decl(witness.ts, 3, 12), Decl(witness.ts, 4, 7)) +>fn : Symbol(fn, Decl(witness.ts, 5, 15)) +>pInit : Symbol(pInit, Decl(witness.ts, 6, 12), Decl(witness.ts, 7, 7)) +>pInit : Symbol(pInit, Decl(witness.ts, 6, 12), Decl(witness.ts, 7, 7)) var pInit: any; ->pInit : Symbol(pInit, Decl(witness.ts, 3, 12), Decl(witness.ts, 4, 7)) +>pInit : Symbol(pInit, Decl(witness.ts, 6, 12), Decl(witness.ts, 7, 7)) } class InitClass { ->InitClass : Symbol(InitClass, Decl(witness.ts, 5, 1)) +>InitClass : Symbol(InitClass, Decl(witness.ts, 8, 1)) x = this.x; ->x : Symbol(InitClass.x, Decl(witness.ts, 6, 17)) ->this.x : Symbol(InitClass.x, Decl(witness.ts, 6, 17)) ->this : Symbol(InitClass, Decl(witness.ts, 5, 1)) ->x : Symbol(InitClass.x, Decl(witness.ts, 6, 17)) +>x : Symbol(InitClass.x, Decl(witness.ts, 9, 17)) +>this.x : Symbol(InitClass.x, Decl(witness.ts, 9, 17)) +>this : Symbol(InitClass, Decl(witness.ts, 8, 1)) +>x : Symbol(InitClass.x, Decl(witness.ts, 9, 17)) fn() { ->fn : Symbol(InitClass.fn, Decl(witness.ts, 7, 15)) +>fn : Symbol(InitClass.fn, Decl(witness.ts, 10, 15)) var y = this.x; ->y : Symbol(y, Decl(witness.ts, 9, 11), Decl(witness.ts, 10, 11)) ->this.x : Symbol(InitClass.x, Decl(witness.ts, 6, 17)) ->this : Symbol(InitClass, Decl(witness.ts, 5, 1)) ->x : Symbol(InitClass.x, Decl(witness.ts, 6, 17)) +>y : Symbol(y, Decl(witness.ts, 12, 11), Decl(witness.ts, 13, 11)) +>this.x : Symbol(InitClass.x, Decl(witness.ts, 9, 17)) +>this : Symbol(InitClass, Decl(witness.ts, 8, 1)) +>x : Symbol(InitClass.x, Decl(witness.ts, 9, 17)) var y: any; ->y : Symbol(y, Decl(witness.ts, 9, 11), Decl(witness.ts, 10, 11)) +>y : Symbol(y, Decl(witness.ts, 12, 11), Decl(witness.ts, 13, 11)) } } // Return type function fnReturn1() { ->fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 12, 1)) +>fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 15, 1)) return fnReturn1(); ->fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 12, 1)) +>fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 15, 1)) } var a: any; ->a : Symbol(a, Decl(witness.ts, 18, 3), Decl(witness.ts, 19, 3)) +>a : Symbol(a, Decl(witness.ts, 21, 3), Decl(witness.ts, 22, 3)) var a = fnReturn1(); ->a : Symbol(a, Decl(witness.ts, 18, 3), Decl(witness.ts, 19, 3)) ->fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 12, 1)) +>a : Symbol(a, Decl(witness.ts, 21, 3), Decl(witness.ts, 22, 3)) +>fnReturn1 : Symbol(fnReturn1, Decl(witness.ts, 15, 1)) function fnReturn2() { ->fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 19, 20)) +>fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 22, 20)) return fnReturn2; ->fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 19, 20)) +>fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 22, 20)) } var fnr2: () => any = fnReturn2(); ->fnr2 : Symbol(fnr2, Decl(witness.ts, 24, 3)) ->fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 19, 20)) +>fnr2 : Symbol(fnr2, Decl(witness.ts, 27, 3)) +>fnReturn2 : Symbol(fnReturn2, Decl(witness.ts, 22, 20)) // Comma var co1 = (co1, 3); ->co1 : Symbol(co1, Decl(witness.ts, 27, 3), Decl(witness.ts, 28, 3)) ->co1 : Symbol(co1, Decl(witness.ts, 27, 3), Decl(witness.ts, 28, 3)) +>co1 : Symbol(co1, Decl(witness.ts, 30, 3)) +>co1 : Symbol(co1, Decl(witness.ts, 30, 3)) -var co1: number; ->co1 : Symbol(co1, Decl(witness.ts, 27, 3), Decl(witness.ts, 28, 3)) +type CommaInference = Assert>; +>CommaInference : Symbol(CommaInference, Decl(witness.ts, 30, 19)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>co1 : Symbol(co1, Decl(witness.ts, 30, 3)) var co2 = (3, 4, co2); ->co2 : Symbol(co2, Decl(witness.ts, 29, 3), Decl(witness.ts, 30, 3)) ->co2 : Symbol(co2, Decl(witness.ts, 29, 3), Decl(witness.ts, 30, 3)) +>co2 : Symbol(co2, Decl(witness.ts, 32, 3), Decl(witness.ts, 33, 3)) +>co2 : Symbol(co2, Decl(witness.ts, 32, 3), Decl(witness.ts, 33, 3)) var co2: any; ->co2 : Symbol(co2, Decl(witness.ts, 29, 3), Decl(witness.ts, 30, 3)) +>co2 : Symbol(co2, Decl(witness.ts, 32, 3), Decl(witness.ts, 33, 3)) var co3 = (co1, co2, co3, co1); ->co3 : Symbol(co3, Decl(witness.ts, 31, 3), Decl(witness.ts, 32, 3)) ->co1 : Symbol(co1, Decl(witness.ts, 27, 3), Decl(witness.ts, 28, 3)) ->co2 : Symbol(co2, Decl(witness.ts, 29, 3), Decl(witness.ts, 30, 3)) ->co3 : Symbol(co3, Decl(witness.ts, 31, 3), Decl(witness.ts, 32, 3)) ->co1 : Symbol(co1, Decl(witness.ts, 27, 3), Decl(witness.ts, 28, 3)) - -var co3: number; ->co3 : Symbol(co3, Decl(witness.ts, 31, 3), Decl(witness.ts, 32, 3)) +>co3 : Symbol(co3, Decl(witness.ts, 34, 3)) +>co1 : Symbol(co1, Decl(witness.ts, 30, 3)) +>co2 : Symbol(co2, Decl(witness.ts, 32, 3), Decl(witness.ts, 33, 3)) +>co3 : Symbol(co3, Decl(witness.ts, 34, 3)) +>co1 : Symbol(co1, Decl(witness.ts, 30, 3)) + +type NestedCommaInference = Assert>; +>NestedCommaInference : Symbol(NestedCommaInference, Decl(witness.ts, 34, 31)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>co3 : Symbol(co3, Decl(witness.ts, 34, 3)) // Assignment var as1 = (as1 = 2); ->as1 : Symbol(as1, Decl(witness.ts, 35, 3), Decl(witness.ts, 36, 3)) ->as1 : Symbol(as1, Decl(witness.ts, 35, 3), Decl(witness.ts, 36, 3)) +>as1 : Symbol(as1, Decl(witness.ts, 38, 3)) +>as1 : Symbol(as1, Decl(witness.ts, 38, 3)) -var as1: number; ->as1 : Symbol(as1, Decl(witness.ts, 35, 3), Decl(witness.ts, 36, 3)) +type AssignmentInference = Assert>; +>AssignmentInference : Symbol(AssignmentInference, Decl(witness.ts, 38, 20)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>as1 : Symbol(as1, Decl(witness.ts, 38, 3)) var as2 = (as2 = as2 = 2); ->as2 : Symbol(as2, Decl(witness.ts, 37, 3), Decl(witness.ts, 38, 3)) ->as2 : Symbol(as2, Decl(witness.ts, 37, 3), Decl(witness.ts, 38, 3)) ->as2 : Symbol(as2, Decl(witness.ts, 37, 3), Decl(witness.ts, 38, 3)) +>as2 : Symbol(as2, Decl(witness.ts, 40, 3)) +>as2 : Symbol(as2, Decl(witness.ts, 40, 3)) +>as2 : Symbol(as2, Decl(witness.ts, 40, 3)) -var as2: number; ->as2 : Symbol(as2, Decl(witness.ts, 37, 3), Decl(witness.ts, 38, 3)) +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : Symbol(NestedAssignmentInference, Decl(witness.ts, 40, 26)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>as2 : Symbol(as2, Decl(witness.ts, 40, 3)) // Conditional var cnd1 = cnd1 ? 0 : 1; ->cnd1 : Symbol(cnd1, Decl(witness.ts, 41, 3), Decl(witness.ts, 42, 3)) ->cnd1 : Symbol(cnd1, Decl(witness.ts, 41, 3), Decl(witness.ts, 42, 3)) +>cnd1 : Symbol(cnd1, Decl(witness.ts, 44, 3)) +>cnd1 : Symbol(cnd1, Decl(witness.ts, 44, 3)) -var cnd1: number; ->cnd1 : Symbol(cnd1, Decl(witness.ts, 41, 3), Decl(witness.ts, 42, 3)) +type ConditionalInference = Assert>; +>ConditionalInference : Symbol(ConditionalInference, Decl(witness.ts, 44, 24)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>cnd1 : Symbol(cnd1, Decl(witness.ts, 44, 3)) var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; ->cnd2 : Symbol(cnd2, Decl(witness.ts, 43, 3), Decl(witness.ts, 44, 3)) ->cnd1 : Symbol(cnd1, Decl(witness.ts, 41, 3), Decl(witness.ts, 42, 3)) ->cnd1 : Symbol(cnd1, Decl(witness.ts, 41, 3), Decl(witness.ts, 42, 3)) +>cnd2 : Symbol(cnd2, Decl(witness.ts, 46, 3), Decl(witness.ts, 47, 3)) +>cnd1 : Symbol(cnd1, Decl(witness.ts, 44, 3)) +>cnd1 : Symbol(cnd1, Decl(witness.ts, 44, 3)) var cnd2: string; ->cnd2 : Symbol(cnd2, Decl(witness.ts, 43, 3), Decl(witness.ts, 44, 3)) +>cnd2 : Symbol(cnd2, Decl(witness.ts, 46, 3), Decl(witness.ts, 47, 3)) // || var or1 = or1 || ''; ->or1 : Symbol(or1, Decl(witness.ts, 47, 3), Decl(witness.ts, 48, 3)) ->or1 : Symbol(or1, Decl(witness.ts, 47, 3), Decl(witness.ts, 48, 3)) +>or1 : Symbol(or1, Decl(witness.ts, 50, 3), Decl(witness.ts, 51, 3)) +>or1 : Symbol(or1, Decl(witness.ts, 50, 3), Decl(witness.ts, 51, 3)) var or1: any; ->or1 : Symbol(or1, Decl(witness.ts, 47, 3), Decl(witness.ts, 48, 3)) +>or1 : Symbol(or1, Decl(witness.ts, 50, 3), Decl(witness.ts, 51, 3)) var or2 = '' || or2; ->or2 : Symbol(or2, Decl(witness.ts, 49, 3), Decl(witness.ts, 50, 3)) ->or2 : Symbol(or2, Decl(witness.ts, 49, 3), Decl(witness.ts, 50, 3)) +>or2 : Symbol(or2, Decl(witness.ts, 52, 3), Decl(witness.ts, 53, 3)) +>or2 : Symbol(or2, Decl(witness.ts, 52, 3), Decl(witness.ts, 53, 3)) var or2: any; ->or2 : Symbol(or2, Decl(witness.ts, 49, 3), Decl(witness.ts, 50, 3)) +>or2 : Symbol(or2, Decl(witness.ts, 52, 3), Decl(witness.ts, 53, 3)) var or3 = or3 || or3; ->or3 : Symbol(or3, Decl(witness.ts, 51, 3), Decl(witness.ts, 52, 3)) ->or3 : Symbol(or3, Decl(witness.ts, 51, 3), Decl(witness.ts, 52, 3)) ->or3 : Symbol(or3, Decl(witness.ts, 51, 3), Decl(witness.ts, 52, 3)) +>or3 : Symbol(or3, Decl(witness.ts, 54, 3), Decl(witness.ts, 55, 3)) +>or3 : Symbol(or3, Decl(witness.ts, 54, 3), Decl(witness.ts, 55, 3)) +>or3 : Symbol(or3, Decl(witness.ts, 54, 3), Decl(witness.ts, 55, 3)) var or3: any; ->or3 : Symbol(or3, Decl(witness.ts, 51, 3), Decl(witness.ts, 52, 3)) +>or3 : Symbol(or3, Decl(witness.ts, 54, 3), Decl(witness.ts, 55, 3)) // && var and1 = and1 && ''; ->and1 : Symbol(and1, Decl(witness.ts, 55, 3), Decl(witness.ts, 56, 3)) ->and1 : Symbol(and1, Decl(witness.ts, 55, 3), Decl(witness.ts, 56, 3)) +>and1 : Symbol(and1, Decl(witness.ts, 58, 3)) +>and1 : Symbol(and1, Decl(witness.ts, 58, 3)) -var and1: string; ->and1 : Symbol(and1, Decl(witness.ts, 55, 3), Decl(witness.ts, 56, 3)) +type LogicalAndInference = Assert>; +>LogicalAndInference : Symbol(LogicalAndInference, Decl(witness.ts, 58, 22)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>and1 : Symbol(and1, Decl(witness.ts, 58, 3)) var and2 = '' && and2; ->and2 : Symbol(and2, Decl(witness.ts, 57, 3), Decl(witness.ts, 58, 3)) ->and2 : Symbol(and2, Decl(witness.ts, 57, 3), Decl(witness.ts, 58, 3)) +>and2 : Symbol(and2, Decl(witness.ts, 60, 3), Decl(witness.ts, 61, 3)) +>and2 : Symbol(and2, Decl(witness.ts, 60, 3), Decl(witness.ts, 61, 3)) var and2: any; ->and2 : Symbol(and2, Decl(witness.ts, 57, 3), Decl(witness.ts, 58, 3)) +>and2 : Symbol(and2, Decl(witness.ts, 60, 3), Decl(witness.ts, 61, 3)) var and3 = and3 && and3; ->and3 : Symbol(and3, Decl(witness.ts, 59, 3), Decl(witness.ts, 60, 3)) ->and3 : Symbol(and3, Decl(witness.ts, 59, 3), Decl(witness.ts, 60, 3)) ->and3 : Symbol(and3, Decl(witness.ts, 59, 3), Decl(witness.ts, 60, 3)) +>and3 : Symbol(and3, Decl(witness.ts, 62, 3), Decl(witness.ts, 63, 3)) +>and3 : Symbol(and3, Decl(witness.ts, 62, 3), Decl(witness.ts, 63, 3)) +>and3 : Symbol(and3, Decl(witness.ts, 62, 3), Decl(witness.ts, 63, 3)) var and3: any; ->and3 : Symbol(and3, Decl(witness.ts, 59, 3), Decl(witness.ts, 60, 3)) +>and3 : Symbol(and3, Decl(witness.ts, 62, 3), Decl(witness.ts, 63, 3)) // function call return type function fnCall() { ->fnCall : Symbol(fnCall, Decl(witness.ts, 60, 14)) +>fnCall : Symbol(fnCall, Decl(witness.ts, 63, 14)) return fnCall(); ->fnCall : Symbol(fnCall, Decl(witness.ts, 60, 14)) +>fnCall : Symbol(fnCall, Decl(witness.ts, 63, 14)) } var fnCallResult = fnCall(); ->fnCallResult : Symbol(fnCallResult, Decl(witness.ts, 66, 3), Decl(witness.ts, 67, 3)) ->fnCall : Symbol(fnCall, Decl(witness.ts, 60, 14)) +>fnCallResult : Symbol(fnCallResult, Decl(witness.ts, 69, 3), Decl(witness.ts, 70, 3)) +>fnCall : Symbol(fnCall, Decl(witness.ts, 63, 14)) var fnCallResult: any; ->fnCallResult : Symbol(fnCallResult, Decl(witness.ts, 66, 3), Decl(witness.ts, 67, 3)) +>fnCallResult : Symbol(fnCallResult, Decl(witness.ts, 69, 3), Decl(witness.ts, 70, 3)) // Call argument function fnArg1(x: typeof fnArg1, y: number) { ->fnArg1 : Symbol(fnArg1, Decl(witness.ts, 67, 22)) ->x : Symbol(x, Decl(witness.ts, 70, 16), Decl(witness.ts, 71, 7)) ->fnArg1 : Symbol(fnArg1, Decl(witness.ts, 67, 22)) ->y : Symbol(y, Decl(witness.ts, 70, 33)) +>fnArg1 : Symbol(fnArg1, Decl(witness.ts, 70, 22)) +>x : Symbol(x, Decl(witness.ts, 73, 16), Decl(witness.ts, 74, 7)) +>fnArg1 : Symbol(fnArg1, Decl(witness.ts, 70, 22)) +>y : Symbol(y, Decl(witness.ts, 73, 33)) var x: (n: typeof fnArg1, m: number) => void; ->x : Symbol(x, Decl(witness.ts, 70, 16), Decl(witness.ts, 71, 7)) ->n : Symbol(n, Decl(witness.ts, 71, 12)) ->fnArg1 : Symbol(fnArg1, Decl(witness.ts, 67, 22)) ->m : Symbol(m, Decl(witness.ts, 71, 29)) +>x : Symbol(x, Decl(witness.ts, 73, 16), Decl(witness.ts, 74, 7)) +>n : Symbol(n, Decl(witness.ts, 74, 12)) +>fnArg1 : Symbol(fnArg1, Decl(witness.ts, 70, 22)) +>m : Symbol(m, Decl(witness.ts, 74, 29)) fnArg1(fnArg1, 0); ->fnArg1 : Symbol(fnArg1, Decl(witness.ts, 67, 22)) ->fnArg1 : Symbol(fnArg1, Decl(witness.ts, 67, 22)) +>fnArg1 : Symbol(fnArg1, Decl(witness.ts, 70, 22)) +>fnArg1 : Symbol(fnArg1, Decl(witness.ts, 70, 22)) } function overload1(x: (n: string) => string): string; ->overload1 : Symbol(overload1, Decl(witness.ts, 73, 1), Decl(witness.ts, 75, 53), Decl(witness.ts, 76, 53), Decl(witness.ts, 77, 44)) ->x : Symbol(x, Decl(witness.ts, 75, 19)) ->n : Symbol(n, Decl(witness.ts, 75, 23)) +>overload1 : Symbol(overload1, Decl(witness.ts, 76, 1), Decl(witness.ts, 78, 53), Decl(witness.ts, 79, 53), Decl(witness.ts, 80, 44)) +>x : Symbol(x, Decl(witness.ts, 78, 19)) +>n : Symbol(n, Decl(witness.ts, 78, 23)) function overload1(x: (n: number) => number): number; ->overload1 : Symbol(overload1, Decl(witness.ts, 73, 1), Decl(witness.ts, 75, 53), Decl(witness.ts, 76, 53), Decl(witness.ts, 77, 44)) ->x : Symbol(x, Decl(witness.ts, 76, 19)) ->n : Symbol(n, Decl(witness.ts, 76, 23)) +>overload1 : Symbol(overload1, Decl(witness.ts, 76, 1), Decl(witness.ts, 78, 53), Decl(witness.ts, 79, 53), Decl(witness.ts, 80, 44)) +>x : Symbol(x, Decl(witness.ts, 79, 19)) +>n : Symbol(n, Decl(witness.ts, 79, 23)) function overload1(x: (n: any) => any): any; ->overload1 : Symbol(overload1, Decl(witness.ts, 73, 1), Decl(witness.ts, 75, 53), Decl(witness.ts, 76, 53), Decl(witness.ts, 77, 44)) ->x : Symbol(x, Decl(witness.ts, 77, 19)) ->n : Symbol(n, Decl(witness.ts, 77, 23)) +>overload1 : Symbol(overload1, Decl(witness.ts, 76, 1), Decl(witness.ts, 78, 53), Decl(witness.ts, 79, 53), Decl(witness.ts, 80, 44)) +>x : Symbol(x, Decl(witness.ts, 80, 19)) +>n : Symbol(n, Decl(witness.ts, 80, 23)) function overload1() { return undefined; }; ->overload1 : Symbol(overload1, Decl(witness.ts, 73, 1), Decl(witness.ts, 75, 53), Decl(witness.ts, 76, 53), Decl(witness.ts, 77, 44)) +>overload1 : Symbol(overload1, Decl(witness.ts, 76, 1), Decl(witness.ts, 78, 53), Decl(witness.ts, 79, 53), Decl(witness.ts, 80, 44)) >undefined : Symbol(undefined) function fnArg2() { ->fnArg2 : Symbol(fnArg2, Decl(witness.ts, 78, 43)) +>fnArg2 : Symbol(fnArg2, Decl(witness.ts, 81, 43)) return overload1(fnArg2); ->overload1 : Symbol(overload1, Decl(witness.ts, 73, 1), Decl(witness.ts, 75, 53), Decl(witness.ts, 76, 53), Decl(witness.ts, 77, 44)) ->fnArg2 : Symbol(fnArg2, Decl(witness.ts, 78, 43)) +>overload1 : Symbol(overload1, Decl(witness.ts, 76, 1), Decl(witness.ts, 78, 53), Decl(witness.ts, 79, 53), Decl(witness.ts, 80, 44)) +>fnArg2 : Symbol(fnArg2, Decl(witness.ts, 81, 43)) } var t = fnArg2(); // t: should be 'any', but is 'string' ->t : Symbol(t, Decl(witness.ts, 83, 3)) ->fnArg2 : Symbol(fnArg2, Decl(witness.ts, 78, 43)) +>t : Symbol(t, Decl(witness.ts, 86, 3)) +>fnArg2 : Symbol(fnArg2, Decl(witness.ts, 81, 43)) // New operator class C { ->C : Symbol(C, Decl(witness.ts, 83, 17)) +>C : Symbol(C, Decl(witness.ts, 86, 17)) fn1() { ->fn1 : Symbol(C.fn1, Decl(witness.ts, 86, 9)) +>fn1 : Symbol(C.fn1, Decl(witness.ts, 89, 9)) return new (this.fn1())(); ->this.fn1 : Symbol(C.fn1, Decl(witness.ts, 86, 9)) ->this : Symbol(C, Decl(witness.ts, 83, 17)) ->fn1 : Symbol(C.fn1, Decl(witness.ts, 86, 9)) +>this.fn1 : Symbol(C.fn1, Decl(witness.ts, 89, 9)) +>this : Symbol(C, Decl(witness.ts, 86, 17)) +>fn1 : Symbol(C.fn1, Decl(witness.ts, 89, 9)) } fn2() { ->fn2 : Symbol(C.fn2, Decl(witness.ts, 89, 5)) +>fn2 : Symbol(C.fn2, Decl(witness.ts, 92, 5)) return new (this.fn2()); ->this.fn2 : Symbol(C.fn2, Decl(witness.ts, 89, 5)) ->this : Symbol(C, Decl(witness.ts, 83, 17)) ->fn2 : Symbol(C.fn2, Decl(witness.ts, 89, 5)) +>this.fn2 : Symbol(C.fn2, Decl(witness.ts, 92, 5)) +>this : Symbol(C, Decl(witness.ts, 86, 17)) +>fn2 : Symbol(C.fn2, Decl(witness.ts, 92, 5)) } fn3() { ->fn3 : Symbol(C.fn3, Decl(witness.ts, 92, 5)) +>fn3 : Symbol(C.fn3, Decl(witness.ts, 95, 5)) var a: new(x) => number; ->a : Symbol(a, Decl(witness.ts, 94, 11)) ->x : Symbol(x, Decl(witness.ts, 94, 19)) +>a : Symbol(a, Decl(witness.ts, 97, 11)) +>x : Symbol(x, Decl(witness.ts, 97, 19)) return new a(this.fn3); ->a : Symbol(a, Decl(witness.ts, 94, 11)) ->this.fn3 : Symbol(C.fn3, Decl(witness.ts, 92, 5)) ->this : Symbol(C, Decl(witness.ts, 83, 17)) ->fn3 : Symbol(C.fn3, Decl(witness.ts, 92, 5)) +>a : Symbol(a, Decl(witness.ts, 97, 11)) +>this.fn3 : Symbol(C.fn3, Decl(witness.ts, 95, 5)) +>this : Symbol(C, Decl(witness.ts, 86, 17)) +>fn3 : Symbol(C.fn3, Decl(witness.ts, 95, 5)) } } function fn5() { ->fn5 : Symbol(fn5, Decl(witness.ts, 97, 1)) +>fn5 : Symbol(fn5, Decl(witness.ts, 100, 1)) var a: new (x) => number; ->a : Symbol(a, Decl(witness.ts, 100, 7)) ->x : Symbol(x, Decl(witness.ts, 100, 16)) +>a : Symbol(a, Decl(witness.ts, 103, 7)) +>x : Symbol(x, Decl(witness.ts, 103, 16)) return new a(fn5); ->a : Symbol(a, Decl(witness.ts, 100, 7)) ->fn5 : Symbol(fn5, Decl(witness.ts, 97, 1)) +>a : Symbol(a, Decl(witness.ts, 103, 7)) +>fn5 : Symbol(fn5, Decl(witness.ts, 100, 1)) } var fn5r = fn5(); // fn5r: should be 'any', but is 'number' ->fn5r : Symbol(fn5r, Decl(witness.ts, 103, 3)) ->fn5 : Symbol(fn5, Decl(witness.ts, 97, 1)) +>fn5r : Symbol(fn5r, Decl(witness.ts, 106, 3)) +>fn5 : Symbol(fn5, Decl(witness.ts, 100, 1)) // Property access var propAcc1 = { ->propAcc1 : Symbol(propAcc1, Decl(witness.ts, 106, 3), Decl(witness.ts, 109, 3)) +>propAcc1 : Symbol(propAcc1, Decl(witness.ts, 109, 3)) m: propAcc1.m ->m : Symbol(m, Decl(witness.ts, 106, 16)) ->propAcc1 : Symbol(propAcc1, Decl(witness.ts, 106, 3), Decl(witness.ts, 109, 3)) +>m : Symbol(m, Decl(witness.ts, 109, 16)) +>propAcc1 : Symbol(propAcc1, Decl(witness.ts, 109, 3)) }; -var propAcc1: { m: any; } ->propAcc1 : Symbol(propAcc1, Decl(witness.ts, 106, 3), Decl(witness.ts, 109, 3)) ->m : Symbol(m, Decl(witness.ts, 109, 15)) +type PropertyAccessInference = Assert>; +>PropertyAccessInference : Symbol(PropertyAccessInference, Decl(witness.ts, 111, 2)) +>Assert : Symbol(Assert, Decl(witness.ts, 0, 55)) +>IsAny : Symbol(IsAny, Decl(witness.ts, 0, 0)) +>propAcc1 : Symbol(propAcc1, Decl(witness.ts, 109, 3)) // Property access of namespace member namespace M2 { ->M2 : Symbol(M2, Decl(witness.ts, 109, 25)) +>M2 : Symbol(M2, Decl(witness.ts, 112, 62)) export var x = M2.x; ->x : Symbol(x, Decl(witness.ts, 113, 14)) ->M2.x : Symbol(x, Decl(witness.ts, 113, 14)) ->M2 : Symbol(M2, Decl(witness.ts, 109, 25)) ->x : Symbol(x, Decl(witness.ts, 113, 14)) +>x : Symbol(x, Decl(witness.ts, 116, 14)) +>M2.x : Symbol(x, Decl(witness.ts, 116, 14)) +>M2 : Symbol(M2, Decl(witness.ts, 112, 62)) +>x : Symbol(x, Decl(witness.ts, 116, 14)) var y = x; ->y : Symbol(y, Decl(witness.ts, 114, 7), Decl(witness.ts, 115, 7)) ->x : Symbol(x, Decl(witness.ts, 113, 14)) +>y : Symbol(y, Decl(witness.ts, 117, 7), Decl(witness.ts, 118, 7)) +>x : Symbol(x, Decl(witness.ts, 116, 14)) var y: any; ->y : Symbol(y, Decl(witness.ts, 114, 7), Decl(witness.ts, 115, 7)) +>y : Symbol(y, Decl(witness.ts, 117, 7), Decl(witness.ts, 118, 7)) } // Property access of class instance type class C2 { ->C2 : Symbol(C2, Decl(witness.ts, 116, 1)) +>C2 : Symbol(C2, Decl(witness.ts, 119, 1)) n = this.n; // n: any ->n : Symbol(C2.n, Decl(witness.ts, 119, 10)) ->this.n : Symbol(C2.n, Decl(witness.ts, 119, 10)) ->this : Symbol(C2, Decl(witness.ts, 116, 1)) ->n : Symbol(C2.n, Decl(witness.ts, 119, 10)) +>n : Symbol(C2.n, Decl(witness.ts, 122, 10)) +>this.n : Symbol(C2.n, Decl(witness.ts, 122, 10)) +>this : Symbol(C2, Decl(witness.ts, 119, 1)) +>n : Symbol(C2.n, Decl(witness.ts, 122, 10)) } var c2inst = new C2().n; ->c2inst : Symbol(c2inst, Decl(witness.ts, 122, 3), Decl(witness.ts, 123, 3)) ->new C2().n : Symbol(C2.n, Decl(witness.ts, 119, 10)) ->C2 : Symbol(C2, Decl(witness.ts, 116, 1)) ->n : Symbol(C2.n, Decl(witness.ts, 119, 10)) +>c2inst : Symbol(c2inst, Decl(witness.ts, 125, 3), Decl(witness.ts, 126, 3)) +>new C2().n : Symbol(C2.n, Decl(witness.ts, 122, 10)) +>C2 : Symbol(C2, Decl(witness.ts, 119, 1)) +>n : Symbol(C2.n, Decl(witness.ts, 122, 10)) var c2inst: any; ->c2inst : Symbol(c2inst, Decl(witness.ts, 122, 3), Decl(witness.ts, 123, 3)) +>c2inst : Symbol(c2inst, Decl(witness.ts, 125, 3), Decl(witness.ts, 126, 3)) // Constructor function property access class C3 { ->C3 : Symbol(C3, Decl(witness.ts, 123, 16)) +>C3 : Symbol(C3, Decl(witness.ts, 126, 16)) static q = C3.q; ->q : Symbol(C3.q, Decl(witness.ts, 126, 10)) ->C3.q : Symbol(C3.q, Decl(witness.ts, 126, 10)) ->C3 : Symbol(C3, Decl(witness.ts, 123, 16)) ->q : Symbol(C3.q, Decl(witness.ts, 126, 10)) +>q : Symbol(C3.q, Decl(witness.ts, 129, 10)) +>C3.q : Symbol(C3.q, Decl(witness.ts, 129, 10)) +>C3 : Symbol(C3, Decl(witness.ts, 126, 16)) +>q : Symbol(C3.q, Decl(witness.ts, 129, 10)) } var qq = C3.q; ->qq : Symbol(qq, Decl(witness.ts, 129, 3), Decl(witness.ts, 130, 3)) ->C3.q : Symbol(C3.q, Decl(witness.ts, 126, 10)) ->C3 : Symbol(C3, Decl(witness.ts, 123, 16)) ->q : Symbol(C3.q, Decl(witness.ts, 126, 10)) +>qq : Symbol(qq, Decl(witness.ts, 132, 3), Decl(witness.ts, 133, 3)) +>C3.q : Symbol(C3.q, Decl(witness.ts, 129, 10)) +>C3 : Symbol(C3, Decl(witness.ts, 126, 16)) +>q : Symbol(C3.q, Decl(witness.ts, 129, 10)) var qq: any; ->qq : Symbol(qq, Decl(witness.ts, 129, 3), Decl(witness.ts, 130, 3)) +>qq : Symbol(qq, Decl(witness.ts, 132, 3), Decl(witness.ts, 133, 3)) // Parentheses - tested a bunch above diff --git a/tsc/testdata/baselines/reference/conformance/witness.types b/tsc/testdata/baselines/reference/conformance/witness.types index 1045a841bb5b4..c9508e950463a 100644 --- a/tsc/testdata/baselines/reference/conformance/witness.types +++ b/tsc/testdata/baselines/reference/conformance/witness.types @@ -1,6 +1,15 @@ //// [tests/cases/conformance/types/witness/witness.ts] //// === witness.ts === +type IsAny = 0 extends (1 & Type) ? true : false; +>IsAny : IsAny +>true : true +>false : false + +type Assert = Condition; +>Assert : Condition +>true : true + // Initializers var varInit = varInit; // any >varInit : any @@ -75,7 +84,8 @@ var co1 = (co1, 3); >co1 : any >3 : 3 -var co1: number; +type CommaInference = Assert>; +>CommaInference : any >co1 : any var co2 = (3, 4, co2); @@ -101,7 +111,8 @@ var co3 = (co1, co2, co3, co1); >co3 : any >co1 : any -var co3: number; +type NestedCommaInference = Assert>; +>NestedCommaInference : any >co3 : any // Assignment @@ -112,7 +123,8 @@ var as1 = (as1 = 2); >as1 : any >2 : 2 -var as1: number; +type AssignmentInference = Assert>; +>AssignmentInference : any >as1 : any var as2 = (as2 = as2 = 2); @@ -124,7 +136,8 @@ var as2 = (as2 = as2 = 2); >as2 : any >2 : 2 -var as2: number; +type NestedAssignmentInference = Assert>; +>NestedAssignmentInference : any >as2 : any // Conditional @@ -135,7 +148,8 @@ var cnd1 = cnd1 ? 0 : 1; >0 : 0 >1 : 1 -var cnd1: number; +type ConditionalInference = Assert>; +>ConditionalInference : any >cnd1 : any var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; @@ -186,7 +200,8 @@ var and1 = and1 && ''; >and1 : any >'' : "" -var and1: string; +type LogicalAndInference = Assert>; +>LogicalAndInference : any >and1 : any var and2 = '' && and2; @@ -346,9 +361,9 @@ var propAcc1 = { >m : any }; -var propAcc1: { m: any; } +type PropertyAccessInference = Assert>; +>PropertyAccessInference : any >propAcc1 : any ->m : any // Property access of namespace member namespace M2 { diff --git a/tsc/testdata/tests/cases/compiler/circularIndexedPropertyInstantiation.ts b/tsc/testdata/tests/cases/compiler/circularIndexedPropertyInstantiation.ts new file mode 100644 index 0000000000000..3aa2e3f2b6f02 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/circularIndexedPropertyInstantiation.ts @@ -0,0 +1,6 @@ +// @target: es2015 +// Repro from #14837 + +type Foo = { "true": Foo> }[T]; +let f1: Foo<"true", {}>; +let f2: Foo<"false", {}>; \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/circularInitializerInference.ts b/tsc/testdata/tests/cases/compiler/circularInitializerInference.ts new file mode 100644 index 0000000000000..727b206a54e83 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/circularInitializerInference.ts @@ -0,0 +1,31 @@ +// @target: es2015 +// @strict: true, false + +export {}; + +type IsAny = 0 extends (1 & Type) ? true : false; +type Assert = Condition; + +var comma = (comma, 3); +type CommaInference = Assert>; + +var nestedComma = (comma, nestedComma, comma); +type NestedCommaInference = Assert>; + +var assignment = (assignment = 2); +type AssignmentInference = Assert>; + +var nestedAssignment = (nestedAssignment = nestedAssignment = 2); +type NestedAssignmentInference = Assert>; + +var conditional = conditional ? 0 : 1; +type ConditionalInference = Assert>; + +var logicalAnd = logicalAnd && ""; +type LogicalAndInference = Assert>; + +var propertyAccess = { member: propertyAccess.member }; +type PropertyAccessInference = Assert>; + +const nonCircular: number = 3; +type NonCircularInference = Assert extends false ? true : false>; \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/classCircularityDiagnostics.ts b/tsc/testdata/tests/cases/compiler/classCircularityDiagnostics.ts new file mode 100644 index 0000000000000..34977b5df2a3d --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/classCircularityDiagnostics.ts @@ -0,0 +1,48 @@ +// @target: esnext +// @noImplicitAny: true, false + +class Direct extends Direct { + static value = 1; + value = 2; +} + +const staticValue = Direct.value; +const instanceValue = new Direct().value; + +class First extends Second {} +class Second extends First {} + +const Expression = class Named extends Named {}; + +class NestedBase extends (class { + static value = 1; + value = 2; +}) {} + +const nestedStaticValue: number = NestedBase.value; +const nestedInstanceValue: number = new NestedBase().value; + +const SelfReferencingBase = class extends (class { + static self = SelfReferencingBase; +}) {}; + +const selfConstructor = SelfReferencingBase.self; + +function mixin {}>(base: Base) { + return class extends base { + static value = 1; + value = 2; + }; +} + +class Mixed extends mixin(NestedBase) {} + +const mixedStaticValue: number = Mixed.value; +const mixedInstanceValue: number = new Mixed().value; + +declare function makeBase(value: number): typeof NestedBase; +class InvalidBaseArgument extends makeBase("invalid") {} +const InvalidExpressionArgument = class extends makeBase("invalid") {}; + +declare function makeInvalidBase(value: number): number; +class InvalidConstructor extends makeInvalidBase("invalid") {} \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/enumMemberTypeCacheConsistency.ts b/tsc/testdata/tests/cases/compiler/enumMemberTypeCacheConsistency.ts new file mode 100644 index 0000000000000..74c113fe04cde --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/enumMemberTypeCacheConsistency.ts @@ -0,0 +1,11 @@ +// @target: esnext +// @strict: true +// @declaration: true + +enum E { + A = 0, + B = E.A.valueOf(), + C = 1, +} + +const member: Extract = E.C; \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/getterCircularityDiagnostics.ts b/tsc/testdata/tests/cases/compiler/getterCircularityDiagnostics.ts new file mode 100644 index 0000000000000..f5533c69336ad --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/getterCircularityDiagnostics.ts @@ -0,0 +1,14 @@ +// @target: es2015 +// @strict: true + +declare const props: Options; + +class Container { + get options() { + return { container: this, ...props } as Options; + } +} + +interface Options { + container?: Container; +} \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts b/tsc/testdata/tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts new file mode 100644 index 0000000000000..33c25e649c64e --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts @@ -0,0 +1,13 @@ +// @target: esnext +// @checkJs: true +// @noImplicitAny: true +// @outDir: out +// @filename: file.js + +/** @param {any} axis @param {any} value */ +function updateElements(axis, value) { + const properties = {}; + const pixel = properties[axis] = value; + const otherPixel = properties[axis] = value; + properties.skip = isNaN(pixel) || isNaN(otherPixel); +} \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/limitDeepInstantiations.ts b/tsc/testdata/tests/cases/compiler/limitDeepInstantiations.ts index ccb48dec686eb..da48116a41865 100644 --- a/tsc/testdata/tests/cases/compiler/limitDeepInstantiations.ts +++ b/tsc/testdata/tests/cases/compiler/limitDeepInstantiations.ts @@ -1,6 +1,10 @@ // @target: es2015 -// Repro from #14837 +// @strict: true -type Foo = { "true": Foo> }[T]; -let f1: Foo<"true", {}>; -let f2: Foo<"false", {}>; +type BuildTuple = + Elements["length"] extends Length ? [] : [unknown, ...BuildTuple]; + +declare const shallow: BuildTuple<8>; +const shallowLength: 8 = shallow.length; + +type Deep = BuildTuple<200>; diff --git a/tsc/testdata/tests/cases/conformance/types/witness/witness.ts b/tsc/testdata/tests/cases/conformance/types/witness/witness.ts index 2c3069ed73fb3..f33ea897b43fa 100644 --- a/tsc/testdata/tests/cases/conformance/types/witness/witness.ts +++ b/tsc/testdata/tests/cases/conformance/types/witness/witness.ts @@ -1,7 +1,8 @@ // @target: es2015 // @strict: false - +type IsAny = 0 extends (1 & Type) ? true : false; +type Assert = Condition; // Initializers var varInit = varInit; // any @@ -31,21 +32,21 @@ var fnr2: () => any = fnReturn2(); // Comma var co1 = (co1, 3); -var co1: number; +type CommaInference = Assert>; var co2 = (3, 4, co2); var co2: any; var co3 = (co1, co2, co3, co1); -var co3: number; +type NestedCommaInference = Assert>; // Assignment var as1 = (as1 = 2); -var as1: number; +type AssignmentInference = Assert>; var as2 = (as2 = as2 = 2); -var as2: number; +type NestedAssignmentInference = Assert>; // Conditional var cnd1 = cnd1 ? 0 : 1; -var cnd1: number; +type ConditionalInference = Assert>; var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; var cnd2: string; @@ -59,7 +60,7 @@ var or3: any; // && var and1 = and1 && ''; -var and1: string; +type LogicalAndInference = Assert>; var and2 = '' && and2; var and2: any; var and3 = and3 && and3; @@ -112,7 +113,7 @@ var fn5r = fn5(); // fn5r: should be 'any', but is 'number' var propAcc1 = { m: propAcc1.m }; -var propAcc1: { m: any; } +type PropertyAccessInference = Assert>; // Property access of namespace member namespace M2 {