diff --git a/internal/checker/checker.go b/internal/checker/checker.go index fca04dd588..31d4728a6b 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -553,306 +553,307 @@ type Host interface { var nextCheckerID atomic.Uint32 type Checker struct { - id uint32 - program Program - compilerOptions *core.CompilerOptions - files []*ast.SourceFile - fileIndexMap map[*ast.SourceFile]int - compareSymbols func(*ast.Symbol, *ast.Symbol) int - compareSymbolChains func([]*ast.Symbol, []*ast.Symbol) int - TypeCount uint32 - SymbolCount uint32 - TotalInstantiationCount uint32 - instantiationCount uint32 - instantiationDepth uint32 - inlineLevel int - currentNode *ast.Node - varianceTypeParameter *Type - languageVersion core.ScriptTarget - moduleKind core.ModuleKind - moduleResolutionKind core.ModuleResolutionKind - isInferencePartiallyBlocked bool - legacyDecorators bool - emitStandardClassFields bool - allowSyntheticDefaultImports bool - strictNullChecks bool - strictFunctionTypes bool - strictBindCallApply bool - strictPropertyInitialization bool - strictBuiltinIteratorReturn bool - noImplicitAny bool - noImplicitThis bool - useUnknownInCatchVariables bool - exactOptionalPropertyTypes bool - canCollectSymbolAliasAccessibilityData bool - wasCanceled bool - arrayVariances []VarianceFlags - globals ast.SymbolTable - globalSymbols []*ast.Symbol - evaluate evaluator.Evaluator - stringLiteralTypes map[string]*Type - numberLiteralTypes map[jsnum.Number]*Type - bigintLiteralTypes map[jsnum.PseudoBigInt]*Type - enumLiteralTypes map[EnumLiteralKey]*Type - indexedAccessTypes map[string]*Type - templateLiteralTypes map[string]*Type - stringMappingTypes map[StringMappingKey]*Type - uniqueESSymbolTypes map[*ast.Symbol]*Type - thisExpandoKinds map[*ast.Symbol]thisAssignmentDeclarationKind - thisExpandoLocations map[*ast.Symbol]*ast.Node - subtypeReductionCache map[string][]*Type - cachedTypes map[CachedTypeKey]*Type - cachedSignatures map[CachedSignatureKey]*Signature - undefinedProperties map[string]*ast.Symbol - narrowedTypes map[NarrowedTypeKey]*Type - assignmentReducedTypes map[AssignmentReducedKey]*Type - discriminatedContextualTypes map[DiscriminatedContextualTypeKey]*Type - instantiationExpressionTypes map[InstantiationExpressionKey]*Type - substitutionTypes map[SubstitutionTypeKey]*Type - reverseMappedCache map[ReverseMappedTypeKey]*Type - reverseHomomorphicMappedCache map[ReverseMappedTypeKey]*Type - iterationTypesCache map[IterationTypesKey]IterationTypes - markerTypes collections.Set[*Type] - undefinedSymbol *ast.Symbol - argumentsSymbol *ast.Symbol - requireSymbol *ast.Symbol - unknownSymbol *ast.Symbol - resolvingSymbol *ast.Symbol - unresolvedSymbols map[string]*ast.Symbol - errorTypes map[string]*Type - globalThisSymbol *ast.Symbol - resolveName func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol - resolveNameForSymbolSuggestion func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol - tupleTypes map[string]*Type - unionTypes map[string]*Type - unionOfUnionTypes map[UnionOfUnionKey]*Type - intersectionTypes map[string]*Type - diagnostics ast.DiagnosticsCollection - suggestionDiagnostics ast.DiagnosticsCollection - symbolPool core.Pool[ast.Symbol] - signaturePool core.Pool[Signature] - indexInfoPool core.Pool[IndexInfo] - mergedSymbols map[*ast.Symbol]*ast.Symbol - factory ast.NodeFactory - nodeLinks core.LinkStore[*ast.Node, NodeLinks] - signatureLinks core.LinkStore[*ast.Node, SignatureLinks] - symbolNodeLinks core.LinkStore[*ast.Node, SymbolNodeLinks] - typeNodeLinks core.LinkStore[*ast.Node, TypeNodeLinks] - enumMemberLinks core.LinkStore[*ast.Node, EnumMemberLinks] - assertionLinks core.LinkStore[*ast.Node, AssertionLinks] - arrayLiteralLinks core.LinkStore[*ast.Node, ArrayLiteralLinks] - switchStatementLinks core.LinkStore[*ast.Node, SwitchStatementLinks] - jsxElementLinks core.LinkStore[*ast.Node, JsxElementLinks] - symbolReferenceLinks core.LinkStore[*ast.Symbol, SymbolReferenceLinks] - valueSymbolLinks core.LinkStore[*ast.Symbol, ValueSymbolLinks] - mappedSymbolLinks core.LinkStore[*ast.Symbol, MappedSymbolLinks] - deferredSymbolLinks core.LinkStore[*ast.Symbol, DeferredSymbolLinks] - aliasSymbolLinks core.LinkStore[*ast.Symbol, AliasSymbolLinks] - moduleSymbolLinks core.LinkStore[*ast.Symbol, ModuleSymbolLinks] - lateBoundLinks core.LinkStore[*ast.Symbol, LateBoundLinks] - exportTypeLinks core.LinkStore[*ast.Symbol, ExportTypeLinks] - membersAndExportsLinks core.LinkStore[*ast.Symbol, MembersAndExportsLinks] - typeAliasLinks core.LinkStore[*ast.Symbol, TypeAliasLinks] - declaredTypeLinks core.LinkStore[*ast.Symbol, DeclaredTypeLinks] - spreadLinks core.LinkStore[*ast.Symbol, SpreadLinks] - varianceLinks core.LinkStore[*ast.Symbol, VarianceLinks] - indexSymbolLinks core.LinkStore[*ast.Symbol, IndexSymbolLinks] - ReverseMappedSymbolLinks core.LinkStore[*ast.Symbol, ReverseMappedSymbolLinks] - markedAssignmentSymbolLinks core.LinkStore[*ast.Symbol, MarkedAssignmentSymbolLinks] - symbolContainerLinks core.LinkStore[*ast.Symbol, ContainingSymbolLinks] - sourceFileLinks core.LinkStore[*ast.SourceFile, SourceFileLinks] - patternForType map[*Type]*ast.Node - contextFreeTypes map[*ast.Node]*Type - anyType *Type - autoType *Type - wildcardType *Type - blockedStringType *Type - errorType *Type - unresolvedType *Type - nonInferrableAnyType *Type - intrinsicMarkerType *Type - unknownType *Type - undefinedType *Type - undefinedWideningType *Type - missingType *Type - undefinedOrMissingType *Type - optionalType *Type - nullType *Type - nullWideningType *Type - stringType *Type - numberType *Type - bigintType *Type - regularFalseType *Type - falseType *Type - regularTrueType *Type - trueType *Type - booleanType *Type - esSymbolType *Type - voidType *Type - neverType *Type - silentNeverType *Type - implicitNeverType *Type - unreachableNeverType *Type - nonPrimitiveType *Type - stringOrNumberType *Type - stringNumberSymbolType *Type - numberOrBigIntType *Type - templateConstraintType *Type - numericStringType *Type - uniqueLiteralType *Type - uniqueLiteralMapper *TypeMapper - reliabilityFlags RelationComparisonResult - reportUnreliableMapper *TypeMapper - reportUnmeasurableMapper *TypeMapper - restrictiveMapper *TypeMapper - permissiveMapper *TypeMapper - emptyObjectType *Type - emptyJsxObjectType *Type - emptyFreshJsxObjectType *Type - emptyTypeLiteralType *Type - unknownEmptyObjectType *Type - unknownUnionType *Type - emptyGenericType *Type - anyFunctionType *Type - noConstraintType *Type - circularConstraintType *Type - resolvingDefaultType *Type - markerSuperType *Type - markerSubType *Type - markerOtherType *Type - markerSuperTypeForCheck *Type - markerSubTypeForCheck *Type - noTypePredicate *TypePredicate - anySignature *Signature - unknownSignature *Signature - resolvingSignature *Signature - silentNeverSignature *Signature - enumNumberIndexInfo *IndexInfo - anyBaseTypeIndexInfo *IndexInfo - patternAmbientModules []*ast.PatternAmbientModule - patternAmbientModuleAugmentations ast.SymbolTable - globalObjectType *Type - globalFunctionType *Type - globalCallableFunctionType *Type - globalNewableFunctionType *Type - globalArrayType *Type - globalReadonlyArrayType *Type - globalStringType *Type - globalNumberType *Type - globalBooleanType *Type - globalRegExpType *Type - globalThisType *Type - anyArrayType *Type - autoArrayType *Type - anyReadonlyArrayType *Type - deferredGlobalImportMetaExpressionType *Type - contextualBindingPatterns []*ast.Node - emptyStringType *Type - zeroType *Type - zeroBigIntType *Type - typeofType *Type - typeResolutions []TypeResolution - resolutionStart int - inVarianceComputation bool - suggestionCount int - apparentArgumentCount *int - lastGetCombinedNodeFlagsNode *ast.Node - lastGetCombinedNodeFlagsResult ast.NodeFlags - lastGetCombinedModifierFlagsNode *ast.Node - lastGetCombinedModifierFlagsResult ast.ModifierFlags - freeinferenceState *InferenceState - freeFlowState *FlowState - flowLoopCache map[FlowLoopKey]*Type - flowLoopStack []FlowLoopInfo - sharedFlows []SharedFlow - antecedentTypes []*Type - flowAnalysisDisabled bool - flowInvocationCount int - flowTypeCache map[*ast.Node]*Type - lastFlowNode *ast.FlowNode - lastFlowNodeReachable bool - flowNodeReachable map[*ast.FlowNode]bool - flowNodePostSuper map[*ast.FlowNode]bool - renamedBindingElementsInTypes []*ast.Node - contextualInfos []ContextualInfo - inferenceContextInfos []InferenceContextInfo - awaitedTypeStack []*Type - reverseMappedSourceStack []*Type - reverseMappedTargetStack []*Type - reverseExpandingFlags ExpandingFlags - freeRelater *Relater - subtypeRelation *Relation - strictSubtypeRelation *Relation - assignableRelation *Relation - comparableRelation *Relation - identityRelation *Relation - enumRelation map[EnumRelationKey]RelationComparisonResult - getGlobalESSymbolType func() *Type - getGlobalBigIntType func() *Type - getGlobalImportMetaType func() *Type - getGlobalImportAttributesType func() *Type - getGlobalImportAttributesTypeChecked func() *Type - getGlobalNonNullableTypeAliasOrNil func() *ast.Symbol - getGlobalExtractSymbol func() *ast.Symbol - getGlobalDisposableType func() *Type - getGlobalAsyncDisposableType func() *Type - getGlobalAwaitedSymbol func() *ast.Symbol - getGlobalAwaitedSymbolOrNil func() *ast.Symbol - getGlobalNaNSymbolOrNil func() *ast.Symbol - getGlobalRecordSymbol func() *ast.Symbol - getGlobalTemplateStringsArrayType func() *Type - getGlobalESSymbolConstructorSymbolOrNil func() *ast.Symbol - getGlobalImportCallOptionsType func() *Type - getGlobalImportCallOptionsTypeChecked func() *Type - getGlobalPromiseType func() *Type - getGlobalPromiseTypeChecked func() *Type - getGlobalPromiseLikeType func() *Type - getGlobalPromiseConstructorSymbol func() *ast.Symbol - getGlobalPromiseConstructorSymbolOrNil func() *ast.Symbol - getGlobalOmitSymbol func() *ast.Symbol - getGlobalNoInferSymbolOrNil func() *ast.Symbol - getGlobalIteratorType func() *Type - getGlobalIterableType func() *Type - getGlobalIterableTypeChecked func() *Type - getGlobalIterableIteratorType func() *Type - getGlobalIterableIteratorTypeChecked func() *Type - getGlobalIteratorObjectType func() *Type - getGlobalGeneratorType func() *Type - getGlobalAsyncIteratorType func() *Type - getGlobalAsyncIterableType func() *Type - getGlobalAsyncIterableTypeChecked func() *Type - getGlobalAsyncIterableIteratorType func() *Type - getGlobalAsyncIterableIteratorTypeChecked func() *Type - getGlobalAsyncIteratorObjectType func() *Type - getGlobalAsyncGeneratorType func() *Type - getGlobalIteratorYieldResultType func() *Type - getGlobalIteratorReturnResultType func() *Type - getGlobalTypedPropertyDescriptorType func() *Type - getGlobalClassDecoratorContextType func() *Type - getGlobalClassMethodDecoratorContextType func() *Type - getGlobalClassGetterDecoratorContextType func() *Type - getGlobalClassSetterDecoratorContextType func() *Type - getGlobalClassAccessorDecoratorContxtType func() *Type - getGlobalClassAccessorDecoratorContextType func() *Type - getGlobalClassAccessorDecoratorTargetType func() *Type - getGlobalClassAccessorDecoratorResultType func() *Type - getGlobalClassFieldDecoratorContextType func() *Type - syncIterationTypesResolver *IterationTypesResolver - asyncIterationTypesResolver *IterationTypesResolver - isPrimitiveOrObjectOrEmptyType func(*Type) bool - containsMissingType func(*Type) bool - couldContainTypeVariables func(*Type) bool - isStringIndexSignatureOnlyType func(*Type) bool - markNodeAssignments func(*ast.Node) bool - emitResolver *emitResolver - emitResolverOnce sync.Once - diagnosticConstructionContext *printer.EmitContext - nodeBuilder *NodeBuilder - _jsxNamespace string - _jsxFactoryEntity *ast.Node - skipDirectInferenceNodes collections.Set[*ast.Node] - ctx context.Context - packagesMap map[string]bool + id uint32 + program Program + compilerOptions *core.CompilerOptions + files []*ast.SourceFile + fileIndexMap map[*ast.SourceFile]int + compareSymbols func(*ast.Symbol, *ast.Symbol) int + compareSymbolChains func([]*ast.Symbol, []*ast.Symbol) int + TypeCount uint32 + SymbolCount uint32 + TotalInstantiationCount uint32 + instantiationCount uint32 + instantiationDepth uint32 + inlineLevel int + currentNode *ast.Node + varianceTypeParameter *Type + languageVersion core.ScriptTarget + moduleKind core.ModuleKind + moduleResolutionKind core.ModuleResolutionKind + isInferencePartiallyBlocked bool + legacyDecorators bool + emitStandardClassFields bool + allowSyntheticDefaultImports bool + strictNullChecks bool + strictFunctionTypes bool + strictBindCallApply bool + strictPropertyInitialization bool + strictBuiltinIteratorReturn bool + noImplicitAny bool + noImplicitThis bool + useUnknownInCatchVariables bool + exactOptionalPropertyTypes bool + canCollectSymbolAliasAccessibilityData bool + wasCanceled bool + arrayVariances []VarianceFlags + globals ast.SymbolTable + globalSymbols []*ast.Symbol + evaluate evaluator.Evaluator + stringLiteralTypes map[string]*Type + numberLiteralTypes map[jsnum.Number]*Type + bigintLiteralTypes map[jsnum.PseudoBigInt]*Type + enumLiteralTypes map[EnumLiteralKey]*Type + indexedAccessTypes map[string]*Type + templateLiteralTypes map[string]*Type + stringMappingTypes map[StringMappingKey]*Type + uniqueESSymbolTypes map[*ast.Symbol]*Type + thisExpandoKinds map[*ast.Symbol]thisAssignmentDeclarationKind + thisExpandoLocations map[*ast.Symbol]*ast.Node + subtypeReductionCache map[string][]*Type + cachedTypes map[CachedTypeKey]*Type + cachedSignatures map[CachedSignatureKey]*Signature + undefinedProperties map[string]*ast.Symbol + narrowedTypes map[NarrowedTypeKey]*Type + assignmentReducedTypes map[AssignmentReducedKey]*Type + discriminatedContextualTypes map[DiscriminatedContextualTypeKey]*Type + instantiationExpressionTypes map[InstantiationExpressionKey]*Type + substitutionTypes map[SubstitutionTypeKey]*Type + reverseMappedCache map[ReverseMappedTypeKey]*Type + reverseHomomorphicMappedCache map[ReverseMappedTypeKey]*Type + iterationTypesCache map[IterationTypesKey]IterationTypes + markerTypes collections.Set[*Type] + undefinedSymbol *ast.Symbol + argumentsSymbol *ast.Symbol + requireSymbol *ast.Symbol + unknownSymbol *ast.Symbol + resolvingSymbol *ast.Symbol + unresolvedSymbols map[string]*ast.Symbol + errorTypes map[string]*Type + globalThisSymbol *ast.Symbol + resolveName func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol + resolveNameForSymbolSuggestion func(location *ast.Node, name string, meaning ast.SymbolFlags, nameNotFoundMessage *diagnostics.Message, isUse bool, excludeGlobals bool) *ast.Symbol + tupleTypes map[string]*Type + unionTypes map[string]*Type + unionOfUnionTypes map[UnionOfUnionKey]*Type + intersectionTypes map[string]*Type + diagnostics ast.DiagnosticsCollection + suggestionDiagnostics ast.DiagnosticsCollection + symbolPool core.Pool[ast.Symbol] + signaturePool core.Pool[Signature] + indexInfoPool core.Pool[IndexInfo] + mergedSymbols map[*ast.Symbol]*ast.Symbol + factory ast.NodeFactory + nodeLinks core.LinkStore[*ast.Node, NodeLinks] + signatureLinks core.LinkStore[*ast.Node, SignatureLinks] + symbolNodeLinks core.LinkStore[*ast.Node, SymbolNodeLinks] + typeNodeLinks core.LinkStore[*ast.Node, TypeNodeLinks] + enumMemberLinks core.LinkStore[*ast.Node, EnumMemberLinks] + assertionLinks core.LinkStore[*ast.Node, AssertionLinks] + arrayLiteralLinks core.LinkStore[*ast.Node, ArrayLiteralLinks] + switchStatementLinks core.LinkStore[*ast.Node, SwitchStatementLinks] + jsxElementLinks core.LinkStore[*ast.Node, JsxElementLinks] + symbolReferenceLinks core.LinkStore[*ast.Symbol, SymbolReferenceLinks] + valueSymbolLinks core.LinkStore[*ast.Symbol, ValueSymbolLinks] + mappedSymbolLinks core.LinkStore[*ast.Symbol, MappedSymbolLinks] + deferredSymbolLinks core.LinkStore[*ast.Symbol, DeferredSymbolLinks] + aliasSymbolLinks core.LinkStore[*ast.Symbol, AliasSymbolLinks] + moduleSymbolLinks core.LinkStore[*ast.Symbol, ModuleSymbolLinks] + lateBoundLinks core.LinkStore[*ast.Symbol, LateBoundLinks] + exportTypeLinks core.LinkStore[*ast.Symbol, ExportTypeLinks] + membersAndExportsLinks core.LinkStore[*ast.Symbol, MembersAndExportsLinks] + typeAliasLinks core.LinkStore[*ast.Symbol, TypeAliasLinks] + declaredTypeLinks core.LinkStore[*ast.Symbol, DeclaredTypeLinks] + spreadLinks core.LinkStore[*ast.Symbol, SpreadLinks] + varianceLinks core.LinkStore[*ast.Symbol, VarianceLinks] + indexSymbolLinks core.LinkStore[*ast.Symbol, IndexSymbolLinks] + ReverseMappedSymbolLinks core.LinkStore[*ast.Symbol, ReverseMappedSymbolLinks] + markedAssignmentSymbolLinks core.LinkStore[*ast.Symbol, MarkedAssignmentSymbolLinks] + symbolContainerLinks core.LinkStore[*ast.Symbol, ContainingSymbolLinks] + sourceFileLinks core.LinkStore[*ast.SourceFile, SourceFileLinks] + patternForType map[*Type]*ast.Node + contextFreeTypes map[*ast.Node]*Type + anyType *Type + autoType *Type + wildcardType *Type + blockedStringType *Type + errorType *Type + unresolvedType *Type + nonInferrableAnyType *Type + intrinsicMarkerType *Type + unknownType *Type + undefinedType *Type + undefinedWideningType *Type + missingType *Type + undefinedOrMissingType *Type + optionalType *Type + nullType *Type + nullWideningType *Type + stringType *Type + numberType *Type + bigintType *Type + regularFalseType *Type + falseType *Type + regularTrueType *Type + trueType *Type + booleanType *Type + esSymbolType *Type + voidType *Type + neverType *Type + silentNeverType *Type + implicitNeverType *Type + unreachableNeverType *Type + nonPrimitiveType *Type + stringOrNumberType *Type + stringNumberSymbolType *Type + numberOrBigIntType *Type + templateConstraintType *Type + numericStringType *Type + uniqueLiteralType *Type + uniqueLiteralMapper *TypeMapper + reliabilityFlags RelationComparisonResult + reportUnreliableMapper *TypeMapper + reportUnmeasurableMapper *TypeMapper + restrictiveMapper *TypeMapper + permissiveMapper *TypeMapper + emptyObjectType *Type + emptyJsxObjectType *Type + emptyFreshJsxObjectType *Type + emptyTypeLiteralType *Type + unknownEmptyObjectType *Type + unknownUnionType *Type + emptyGenericType *Type + anyFunctionType *Type + noConstraintType *Type + circularConstraintType *Type + resolvingDefaultType *Type + markerSuperType *Type + markerSubType *Type + markerOtherType *Type + markerSuperTypeForCheck *Type + markerSubTypeForCheck *Type + noTypePredicate *TypePredicate + anySignature *Signature + unknownSignature *Signature + resolvingSignature *Signature + silentNeverSignature *Signature + enumNumberIndexInfo *IndexInfo + anyBaseTypeIndexInfo *IndexInfo + patternAmbientModules []*ast.PatternAmbientModule + patternAmbientModuleAugmentations ast.SymbolTable + globalObjectType *Type + globalFunctionType *Type + globalCallableFunctionType *Type + globalNewableFunctionType *Type + globalArrayType *Type + globalReadonlyArrayType *Type + globalStringType *Type + globalNumberType *Type + globalBooleanType *Type + globalRegExpType *Type + globalThisType *Type + anyArrayType *Type + autoArrayType *Type + anyReadonlyArrayType *Type + deferredGlobalImportMetaExpressionType *Type + contextualBindingPatterns []*ast.Node + emptyStringType *Type + zeroType *Type + zeroBigIntType *Type + typeofType *Type + typeResolutions []TypeResolution + resolutionStart int + inVarianceComputation bool + suggestionCount int + apparentArgumentCount *int + lastGetCombinedNodeFlagsNode *ast.Node + lastGetCombinedNodeFlagsResult ast.NodeFlags + lastGetCombinedModifierFlagsNode *ast.Node + lastGetCombinedModifierFlagsResult ast.ModifierFlags + freeinferenceState *InferenceState + freeFlowState *FlowState + flowLoopCache map[FlowLoopKey]*Type + flowLoopStack []FlowLoopInfo + sharedFlows []SharedFlow + antecedentTypes []*Type + flowAnalysisDisabled bool + flowInvocationCount int + flowTypeCache map[*ast.Node]*Type + lastFlowNode *ast.FlowNode + lastFlowNodeReachable bool + flowNodeReachable map[*ast.FlowNode]bool + flowNodePostSuper map[*ast.FlowNode]bool + renamedBindingElementsInTypes []*ast.Node + contextualInfos []ContextualInfo + inferenceContextInfos []InferenceContextInfo + awaitedTypeStack []*Type + reverseMappedSourceStack []*Type + reverseMappedTargetStack []*Type + reverseExpandingFlags ExpandingFlags + freeRelater *Relater + subtypeRelation *Relation + strictSubtypeRelation *Relation + assignableRelation *Relation + comparableRelation *Relation + identityRelation *Relation + enumRelation map[EnumRelationKey]RelationComparisonResult + getGlobalESSymbolType func() *Type + getGlobalBigIntType func() *Type + getGlobalImportMetaType func() *Type + getGlobalImportAttributesType func() *Type + getGlobalImportAttributesTypeChecked func() *Type + getGlobalNonNullableTypeAliasOrNil func() *ast.Symbol + getGlobalExtractSymbol func() *ast.Symbol + getGlobalDisposableType func() *Type + getGlobalAsyncDisposableType func() *Type + getGlobalAwaitedSymbol func() *ast.Symbol + getGlobalAwaitedSymbolOrNil func() *ast.Symbol + getGlobalNaNSymbolOrNil func() *ast.Symbol + getGlobalRecordSymbol func() *ast.Symbol + getGlobalTemplateStringsArrayType func() *Type + getGlobalESSymbolConstructorSymbolOrNil func() *ast.Symbol + getGlobalESSymbolConstructorTypeSymbolOrNil func() *ast.Symbol + getGlobalImportCallOptionsType func() *Type + getGlobalImportCallOptionsTypeChecked func() *Type + getGlobalPromiseType func() *Type + getGlobalPromiseTypeChecked func() *Type + getGlobalPromiseLikeType func() *Type + getGlobalPromiseConstructorSymbol func() *ast.Symbol + getGlobalPromiseConstructorSymbolOrNil func() *ast.Symbol + getGlobalOmitSymbol func() *ast.Symbol + getGlobalNoInferSymbolOrNil func() *ast.Symbol + getGlobalIteratorType func() *Type + getGlobalIterableType func() *Type + getGlobalIterableTypeChecked func() *Type + getGlobalIterableIteratorType func() *Type + getGlobalIterableIteratorTypeChecked func() *Type + getGlobalIteratorObjectType func() *Type + getGlobalGeneratorType func() *Type + getGlobalAsyncIteratorType func() *Type + getGlobalAsyncIterableType func() *Type + getGlobalAsyncIterableTypeChecked func() *Type + getGlobalAsyncIterableIteratorType func() *Type + getGlobalAsyncIterableIteratorTypeChecked func() *Type + getGlobalAsyncIteratorObjectType func() *Type + getGlobalAsyncGeneratorType func() *Type + getGlobalIteratorYieldResultType func() *Type + getGlobalIteratorReturnResultType func() *Type + getGlobalTypedPropertyDescriptorType func() *Type + getGlobalClassDecoratorContextType func() *Type + getGlobalClassMethodDecoratorContextType func() *Type + getGlobalClassGetterDecoratorContextType func() *Type + getGlobalClassSetterDecoratorContextType func() *Type + getGlobalClassAccessorDecoratorContxtType func() *Type + getGlobalClassAccessorDecoratorContextType func() *Type + getGlobalClassAccessorDecoratorTargetType func() *Type + getGlobalClassAccessorDecoratorResultType func() *Type + getGlobalClassFieldDecoratorContextType func() *Type + syncIterationTypesResolver *IterationTypesResolver + asyncIterationTypesResolver *IterationTypesResolver + isPrimitiveOrObjectOrEmptyType func(*Type) bool + containsMissingType func(*Type) bool + couldContainTypeVariables func(*Type) bool + isStringIndexSignatureOnlyType func(*Type) bool + markNodeAssignments func(*ast.Node) bool + emitResolver *emitResolver + emitResolverOnce sync.Once + diagnosticConstructionContext *printer.EmitContext + nodeBuilder *NodeBuilder + _jsxNamespace string + _jsxFactoryEntity *ast.Node + skipDirectInferenceNodes collections.Set[*ast.Node] + ctx context.Context + packagesMap map[string]bool } func NewChecker(program Program) *Checker { @@ -1029,6 +1030,7 @@ func NewChecker(program Program) *Checker { c.getGlobalRecordSymbol = c.getGlobalTypeAliasResolver("Record", 2 /*arity*/, true /*reportErrors*/) c.getGlobalTemplateStringsArrayType = c.getGlobalTypeResolver("TemplateStringsArray", 0 /*arity*/, true /*reportErrors*/) c.getGlobalESSymbolConstructorSymbolOrNil = c.getGlobalValueSymbolResolver("Symbol", false /*reportErrors*/) + c.getGlobalESSymbolConstructorTypeSymbolOrNil = c.getGlobalTypeSymbolResolver("SymbolConstructor", false /*reportErrors*/) c.getGlobalImportCallOptionsType = c.getGlobalTypeResolver("ImportCallOptions", 0 /*arity*/, false /*reportErrors*/) c.getGlobalImportCallOptionsTypeChecked = c.getGlobalTypeResolver("ImportCallOptions", 0 /*arity*/, true /*reportErrors*/) c.getGlobalPromiseType = c.getGlobalTypeResolver("Promise", 1 /*arity*/, false /*reportErrors*/) @@ -1131,6 +1133,12 @@ func (c *Checker) getGlobalValueSymbolResolver(name string, reportErrors bool) f }) } +func (c *Checker) getGlobalTypeSymbolResolver(name string, reportErrors bool) func() *ast.Symbol { + return core.Memoize(func() *ast.Symbol { + return c.getGlobalSymbol(name, ast.SymbolFlagsType, core.IfElse(reportErrors, diagnostics.Cannot_find_global_type_0, nil)) + }) +} + func (c *Checker) getGlobalTypesResolver(names []string, arity int, reportErrors bool) func() []*Type { return core.Memoize(func() []*Type { return core.Map(names, func(name string) *Type { @@ -17313,11 +17321,24 @@ func (c *Checker) isConstructorDeclaredThisProperty(symbol *ast.Symbol) (thisAss return kind, location } +func (c *Checker) isGlobalSymbolConstructor(node *ast.Node) bool { + symbol := c.getSymbolOfNode(node) + globalSymbol := c.getGlobalESSymbolConstructorTypeSymbolOrNil() + return globalSymbol != nil && symbol == globalSymbol +} + func (c *Checker) widenTypeForVariableLikeDeclaration(t *Type, declaration *ast.Node, reportErrors bool) *Type { if t != nil { + // This special case is required for backwards compatibility with libraries that merge a `symbol` property into `SymbolConstructor`. + // See https://github.com/microsoft/typescript-go/issues/1212 + if t.flags&TypeFlagsESSymbol != 0 && c.isGlobalSymbolConstructor(declaration.Parent) { + t = c.getESSymbolLikeTypeForNode(declaration) + } + if reportErrors { c.reportErrorsFromWidening(declaration, t, WideningKindNormal) } + // always widen a 'unique symbol' type if the type was created for a different declaration. if t.flags&TypeFlagsUniqueESSymbol != 0 && (ast.IsBindingElement(declaration) || declaration.Type() == nil) && t.symbol != c.getSymbolOfDeclaration(declaration) { t = c.esSymbolType diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt deleted file mode 100644 index faac1e7fee..0000000000 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -symbolObserverMismatchingPolyfillsWorkTogether.ts(5,14): error TS2717: Subsequent property declarations must have the same type. Property 'observer' must be of type 'symbol', but here has type 'unique symbol'. - - -==== symbolObserverMismatchingPolyfillsWorkTogether.ts (1 errors) ==== - interface SymbolConstructor { - readonly observer: symbol; - } - interface SymbolConstructor { - readonly observer: unique symbol; - ~~~~~~~~ -!!! error TS2717: Subsequent property declarations must have the same type. Property 'observer' must be of type 'symbol', but here has type 'unique symbol'. -!!! related TS6203 symbolObserverMismatchingPolyfillsWorkTogether.ts:2:14: 'observer' was also declared here. - } - - const obj = { - [Symbol.observer]: 0 - }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt.diff deleted file mode 100644 index 6ce57661e1..0000000000 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.errors.txt.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.symbolObserverMismatchingPolyfillsWorkTogether.errors.txt -+++ new.symbolObserverMismatchingPolyfillsWorkTogether.errors.txt -@@= skipped -0, +0 lines =@@ -- -+symbolObserverMismatchingPolyfillsWorkTogether.ts(5,14): error TS2717: Subsequent property declarations must have the same type. Property 'observer' must be of type 'symbol', but here has type 'unique symbol'. -+ -+ -+==== symbolObserverMismatchingPolyfillsWorkTogether.ts (1 errors) ==== -+ interface SymbolConstructor { -+ readonly observer: symbol; -+ } -+ interface SymbolConstructor { -+ readonly observer: unique symbol; -+ ~~~~~~~~ -+!!! error TS2717: Subsequent property declarations must have the same type. Property 'observer' must be of type 'symbol', but here has type 'unique symbol'. -+!!! related TS6203 symbolObserverMismatchingPolyfillsWorkTogether.ts:2:14: 'observer' was also declared here. -+ } -+ -+ const obj = { -+ [Symbol.observer]: 0 -+ }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js index 1e9ef1eea5..b899cb11ba 100644 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js +++ b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js @@ -26,5 +26,5 @@ interface SymbolConstructor { readonly observer: unique symbol; } declare const obj: { - [x: symbol]: number; + [Symbol.observer]: number; }; diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js.diff b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js.diff deleted file mode 100644 index 67fd2964e5..0000000000 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.js.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.symbolObserverMismatchingPolyfillsWorkTogether.js -+++ new.symbolObserverMismatchingPolyfillsWorkTogether.js -@@= skipped -25, +25 lines =@@ - readonly observer: unique symbol; - } - declare const obj: { -- [Symbol.observer]: number; -+ [x: symbol]: number; - }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types index fff0d2858c..3a1a4e9da1 100644 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types +++ b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types @@ -3,22 +3,22 @@ === symbolObserverMismatchingPolyfillsWorkTogether.ts === interface SymbolConstructor { readonly observer: symbol; ->observer : symbol +>observer : unique symbol } interface SymbolConstructor { readonly observer: unique symbol; ->observer : symbol +>observer : unique symbol } const obj = { ->obj : { [x: symbol]: number; } ->{ [Symbol.observer]: 0} : { [x: symbol]: number; } +>obj : { [Symbol.observer]: number; } +>{ [Symbol.observer]: 0} : { [Symbol.observer]: number; } [Symbol.observer]: 0 >[Symbol.observer] : number ->Symbol.observer : symbol +>Symbol.observer : unique symbol >Symbol : SymbolConstructor ->observer : symbol +>observer : unique symbol >0 : 0 }; diff --git a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types.diff b/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types.diff deleted file mode 100644 index 3ba4b8f9d9..0000000000 --- a/testdata/baselines/reference/submodule/compiler/symbolObserverMismatchingPolyfillsWorkTogether.types.diff +++ /dev/null @@ -1,31 +0,0 @@ ---- old.symbolObserverMismatchingPolyfillsWorkTogether.types -+++ new.symbolObserverMismatchingPolyfillsWorkTogether.types -@@= skipped -2, +2 lines =@@ - === symbolObserverMismatchingPolyfillsWorkTogether.ts === - interface SymbolConstructor { - readonly observer: symbol; -->observer : unique symbol -+>observer : symbol - } - interface SymbolConstructor { - readonly observer: unique symbol; -->observer : unique symbol -+>observer : symbol - } - - const obj = { -->obj : { [Symbol.observer]: number; } -->{ [Symbol.observer]: 0} : { [Symbol.observer]: number; } -+>obj : { [x: symbol]: number; } -+>{ [Symbol.observer]: 0} : { [x: symbol]: number; } - - [Symbol.observer]: 0 - >[Symbol.observer] : number -->Symbol.observer : unique symbol -+>Symbol.observer : symbol - >Symbol : SymbolConstructor -->observer : unique symbol -+>observer : symbol - >0 : 0 - - }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js index 3ed2223c95..680d7c869c 100644 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js +++ b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js @@ -58,9 +58,11 @@ declare global { readonly obs: symbol; } } +declare const observable: typeof Symbol.obs; export declare class MyObservable { - [x: symbol]: () => this; private _val; constructor(_val: T); subscribe(next: (val: T) => void): void; + [observable](): this; } +export {}; diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff index d108f7ff87..6dd3df58e9 100644 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff +++ b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff @@ -7,17 +7,4 @@ + _val; constructor(_val) { this._val = _val; - } -@@= skipped -22, +23 lines =@@ - readonly obs: symbol; - } - } --declare const observable: typeof Symbol.obs; - export declare class MyObservable { -+ [x: symbol]: () => this; - private _val; - constructor(_val: T); - subscribe(next: (val: T) => void): void; -- [observable](): this; - } --export {}; \ No newline at end of file + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.types b/testdata/baselines/reference/submodule/conformance/symbolProperty61.types index 6e25b8600e..7e6482c2a0 100644 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.types +++ b/testdata/baselines/reference/submodule/conformance/symbolProperty61.types @@ -6,18 +6,18 @@ declare global { interface SymbolConstructor { readonly obs: symbol ->obs : symbol +>obs : unique symbol } } const observable: typeof Symbol.obs = Symbol.obs ->observable : symbol ->Symbol.obs : symbol +>observable : unique symbol +>Symbol.obs : unique symbol >Symbol : SymbolConstructor ->obs : symbol ->Symbol.obs : symbol +>obs : unique symbol +>Symbol.obs : unique symbol >Symbol : SymbolConstructor ->obs : symbol +>obs : unique symbol export class MyObservable { >MyObservable : MyObservable @@ -40,7 +40,7 @@ export class MyObservable { [observable]() { >[observable] : () => this ->observable : symbol +>observable : unique symbol return this >this : this @@ -52,9 +52,9 @@ type InteropObservable = { [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } >[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } ->Symbol.obs : symbol +>Symbol.obs : unique symbol >Symbol : SymbolConstructor ->obs : symbol +>obs : unique symbol >subscribe : (next: (val: T) => void) => void >next : (val: T) => void >val : T @@ -68,9 +68,9 @@ function from(obs: InteropObservable) { >obs[Symbol.obs]() : { subscribe(next: (val: T) => void): void; } >obs[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } >obs : InteropObservable ->Symbol.obs : symbol +>Symbol.obs : unique symbol >Symbol : SymbolConstructor ->obs : symbol +>obs : unique symbol } from(new MyObservable(42)) diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.types.diff b/testdata/baselines/reference/submodule/conformance/symbolProperty61.types.diff deleted file mode 100644 index 0e497c9e31..0000000000 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.types.diff +++ /dev/null @@ -1,62 +0,0 @@ ---- old.symbolProperty61.types -+++ new.symbolProperty61.types -@@= skipped -5, +5 lines =@@ - - interface SymbolConstructor { - readonly obs: symbol -->obs : unique symbol -+>obs : symbol - } - } - - const observable: typeof Symbol.obs = Symbol.obs -->observable : unique symbol -->Symbol.obs : unique symbol -->Symbol : SymbolConstructor -->obs : unique symbol -->Symbol.obs : unique symbol -->Symbol : SymbolConstructor -->obs : unique symbol -+>observable : symbol -+>Symbol.obs : symbol -+>Symbol : SymbolConstructor -+>obs : symbol -+>Symbol.obs : symbol -+>Symbol : SymbolConstructor -+>obs : symbol - - export class MyObservable { - >MyObservable : MyObservable -@@= skipped -34, +34 lines =@@ - - [observable]() { - >[observable] : () => this -->observable : unique symbol -+>observable : symbol - - return this - >this : this -@@= skipped -12, +12 lines =@@ - - [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } - >[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } -->Symbol.obs : unique symbol -+>Symbol.obs : symbol - >Symbol : SymbolConstructor -->obs : unique symbol -+>obs : symbol - >subscribe : (next: (val: T) => void) => void - >next : (val: T) => void - >val : T -@@= skipped -16, +16 lines =@@ - >obs[Symbol.obs]() : { subscribe(next: (val: T) => void): void; } - >obs[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } - >obs : InteropObservable -->Symbol.obs : unique symbol -+>Symbol.obs : symbol - >Symbol : SymbolConstructor -->obs : unique symbol -+>obs : symbol - } - - from(new MyObservable(42)) \ No newline at end of file