From 5634e586cb31f7d942e7dce99a788f4fffb03c1c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:44:36 -0700 Subject: [PATCH 1/5] init --- internal/checker/nodebuilderimpl.go | 17 +- internal/checker/pseudotypenodebuilder.go | 141 ++++++++++++----- internal/pseudochecker/lookup.go | 59 ++++--- internal/pseudochecker/type.go | 32 +++- .../computedPropertiesNarrowed.errors.txt | 70 ++++----- ...computedPropertiesNarrowed.errors.txt.diff | 130 ++------------- ...tedDeclarationErrorsExpressions.errors.txt | 12 +- ...clarationErrorsExpressions.errors.txt.diff | 33 +--- ...solatedDeclarationErrorsObjects.errors.txt | 63 ++++---- ...edDeclarationErrorsObjects.errors.txt.diff | 148 ------------------ .../isolatedDeclarationLazySymbols.errors.txt | 14 +- ...atedDeclarationLazySymbols.errors.txt.diff | 34 ---- 12 files changed, 270 insertions(+), 483 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt.diff diff --git a/internal/checker/nodebuilderimpl.go b/internal/checker/nodebuilderimpl.go index 9c74c6db022..4830e86fe0e 100644 --- a/internal/checker/nodebuilderimpl.go +++ b/internal/checker/nodebuilderimpl.go @@ -134,6 +134,17 @@ func (b *NodeBuilderImpl) saveRestoreFlags() func() { } } +// inferenceFallbackReporter returns a reporter func for use with pseudoTypeEquivalentToType. +// Returns nil when inference fallback reporting is suppressed, otherwise returns the tracker's +// ReportInferenceFallback. Error nodes for object/array literal children are already stored in +// PseudoTypeInferred.ErrorNodes during pseudochecker construction and reported inline. +func (b *NodeBuilderImpl) inferenceFallbackReporter() func(*ast.Node) { + if b.ctx.suppressReportInferenceFallback { + return nil + } + return b.ctx.tracker.ReportInferenceFallback +} + func (b *NodeBuilderImpl) checkTruncationLength() bool { if b.ctx.truncating { return b.ctx.truncating @@ -1977,7 +1988,7 @@ func (b *NodeBuilderImpl) serializeReturnTypeForSignature(signature *Signature, declarationSymbol := b.ch.getSymbolOfDeclaration(signature.declaration) restore := b.addSymbolTypeToContext(declarationSymbol, returnType) pt := b.pc.GetReturnTypeOfSignature(signature.declaration) - if b.pseudoTypeEquivalentToType(pt, returnType, false, !b.ctx.suppressReportInferenceFallback) { + if b.pseudoTypeEquivalentToType(pt, returnType, false, b.inferenceFallbackReporter()) { // Also verify the pseudo type captures any inferred type predicate, not just the boolean return type. // The pseudochecker is unaware of inferred type predicates, so it produces boolean where // the checker infers e.g. `x is string`. @@ -2088,7 +2099,7 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati } else { pt = b.pc.GetTypeOfDeclaration(declaration) } - if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameter(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), !b.ctx.suppressReportInferenceFallback) { + if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameter(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), b.inferenceFallbackReporter()) { // !!! TODO: If annotated type node is a reference with insufficient type arguments, we should still fall back to type serialization // see: canReuseTypeNodeAnnotation in strada for context ptt := b.pseudoTypeToType(pt) @@ -2098,7 +2109,7 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati result = b.pseudoTypeToNode(pt) } else if requiresAddingUndefined { pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined}) - if b.pseudoTypeEquivalentToType(pt, t, false, !b.ctx.suppressReportInferenceFallback) { + if b.pseudoTypeEquivalentToType(pt, t, false, b.inferenceFallbackReporter()) { result = b.pseudoTypeToNode(pt) } } diff --git a/internal/checker/pseudotypenodebuilder.go b/internal/checker/pseudotypenodebuilder.go index 6fcf61b56f3..f24585b2f4d 100644 --- a/internal/checker/pseudotypenodebuilder.go +++ b/internal/checker/pseudotypenodebuilder.go @@ -16,7 +16,13 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod return b.reuseTypeNode(t.AsPseudoTypeDirect().TypeNode) case pseudochecker.PseudoTypeKindInferred: node := t.AsPseudoTypeInferred().Expression - b.ctx.tracker.ReportInferenceFallback(node) + if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + b.ctx.tracker.ReportInferenceFallback(n) + } + } else { + b.ctx.tracker.ReportInferenceFallback(node) + } // use symbol type from parent declaration to automatically handle expression type widening without duplicating logic if ast.IsReturnStatement(node.Parent) { enclosing := ast.GetContainingFunction(node) @@ -36,7 +42,13 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod return b.typeToTypeNode(ty) case pseudochecker.PseudoTypeKindNoResult: node := t.AsPseudoTypeNoResult().Declaration - b.ctx.tracker.ReportInferenceFallback(node) + if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + b.ctx.tracker.ReportInferenceFallback(n) + } + } else { + b.ctx.tracker.ReportInferenceFallback(node) + } if ast.IsFunctionLike(node) && !ast.IsAccessor(node) { return b.serializeReturnTypeForSignature(b.ch.getSignatureFromDeclaration(node), false) } @@ -153,6 +165,12 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod isConst := b.ch.isConstContext(elements[0].Name) newElements := make([]*ast.Node, 0, len(elements)) + // Suppress inference fallback reporting during object literal element construction. + // Errors on failing elements are already reported during the comparison phase via ErrorNodes; + // this matches strada's noInferenceFallback = true during nested construction. + oldSuppressReportInferenceFallback := b.ctx.suppressReportInferenceFallback + b.ctx.suppressReportInferenceFallback = true + for _, e := range elements { var modifiers *ast.ModifierList if isConst || (e.Kind == pseudochecker.PseudoObjectElementKindPropertyAssignment && e.AsPseudoPropertyAssignment().Readonly) { @@ -235,6 +253,7 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod } newElements = append(newElements, newProp) } + b.ctx.suppressReportInferenceFallback = oldSuppressReportInferenceFallback result := b.f.NewTypeLiteralNode(b.f.NewNodeList(newElements)) if b.ctx.flags&nodebuilder.FlagsMultilineObjectLiterals == 0 { b.e.AddEmitFlags(result, printer.EFSingleLine) @@ -280,7 +299,10 @@ func (b *NodeBuilderImpl) pseudoParameterToNode(p *pseudochecker.PseudoParameter // see `typeNodeIsEquivalentToType` in strada, but applied more broadly here, so is setup to handle more equivalences - strada only used it via // the `canReuseTypeNodeAnnotation` host hook and not the `canReuseTypeNode` hook, which meant locations using the later were reliant on // over-invalidation by the ID inference engine to not emit incorrect types. -func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType, type_ *Type, isOptionalAnnotated bool, reportErrors bool) bool { +// reporter, when non-nil, is called on failure with the node to report the error on. For structural types +// like ObjectLiteral, per-element reporters are created that bind to each property's declaration, so errors +// propagate to the innermost failing leaf rather than firing on intermediate structural containers. +func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType, type_ *Type, isOptionalAnnotated bool, reporter func(*ast.Node)) bool { // if type_ resolves to an error, we charitably assume equality, since we might be in a single-file checking mode if type_ != nil && b.ch.isErrorType(type_) { return true @@ -347,16 +369,16 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } } if targetProp == nil { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if reporter != nil { + reporter(e.Name.Parent) } return false } } targetIsOptional := targetProp.Flags&ast.SymbolFlagsOptional != 0 if e.Optional != targetIsOptional { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if reporter != nil { + reporter(e.Name.Parent) } return false } @@ -365,9 +387,20 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType switch e.Kind { case pseudochecker.PseudoObjectElementKindPropertyAssignment: d := e.AsPseudoPropertyAssignment() - if !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, nil) { + if reporter != nil { + // If the property's type has specific error nodes from construction + // (e.g. spread, shorthand, computed names), report on those. + // For structural types (ObjectLiteral/Tuple/Signature), don't report + // here — the outer fallback to checker-based serialization handles them. + // Otherwise report on the property itself. + if errorNodes := d.Type.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + reporter(n) + } + } else if !isStructuralPseudoType(d.Type) { + reporter(e.Name.Parent) + } } return false } @@ -379,17 +412,17 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType continue } if len(targetSig.parameters) != len(d.Parameters) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if reporter != nil { + reporter(e.Name.Parent) } return false } for i, p := range d.Parameters { targetParam := targetSig.parameters[i] paramType := b.ch.getTypeOfParameter(targetParam) - if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, nil) { + if reporter != nil { + reporter(e.Name.Parent) } return false } @@ -397,31 +430,31 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType targetPredicate := b.ch.getTypePredicateOfSignature(targetSig) if targetPredicate != nil { if !b.pseudoReturnTypeMatchesPredicate(d.ReturnType, targetPredicate) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if reporter != nil { + reporter(e.Name.Parent) } return false } - } else if !b.pseudoTypeEquivalentToType(d.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + } else if !b.pseudoTypeEquivalentToType(d.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, nil) { + if reporter != nil { + reporter(e.Name.Parent) } return false } case pseudochecker.PseudoObjectElementKindGetAccessor: d := e.AsPseudoGetAccessor() - if !b.pseudoTypeEquivalentToType(d.Type, propType, false, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(d.Type, propType, false, nil) { + if reporter != nil { + reporter(e.Name.Parent) } return false } case pseudochecker.PseudoObjectElementKindSetAccessor: d := e.AsPseudoSetAccessor() writeType := b.ch.getWriteTypeOfSymbol(targetProp) - if !b.pseudoTypeEquivalentToType(d.Parameter.Type, writeType, false, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(d.Parameter.Type, writeType, false, nil) { + if reporter != nil { + reporter(e.Name.Parent) } return false } @@ -444,7 +477,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType return false } for i, elem := range pt.Elements { - if !b.pseudoTypeEquivalentToType(elem, elementTypes[i], false, reportErrors) { + if !b.pseudoTypeEquivalentToType(elem, elementTypes[i], false, reporter) { return false } } @@ -456,29 +489,29 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } pt := t.AsPseudoTypeSingleCallSignature() if len(targetSig.typeParameters) != len(pt.TypeParameters) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(pt.Signature) + if reporter != nil { + reporter(pt.Signature) } return false } if len(targetSig.parameters) != len(pt.Parameters) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(pt.Signature) + if reporter != nil { + reporter(pt.Signature) } return false // TODO: spread tuple params may mess with this check } for i, p := range pt.Parameters { targetParam := targetSig.parameters[i] if p.Optional != b.ch.isOptionalParameter(targetParam.ValueDeclaration) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(p.Name.Parent) + if reporter != nil { + reporter(p.Name.Parent) } return false } paramType := b.ch.getTypeOfParameter(targetParam) - if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, false) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(p.Name.Parent) + if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, nil) { + if reporter != nil { + reporter(p.Name.Parent) } return false } @@ -486,24 +519,36 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType targetPredicate := b.ch.getTypePredicateOfSignature(targetSig) if targetPredicate != nil { if !b.pseudoReturnTypeMatchesPredicate(pt.ReturnType, targetPredicate) { - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(pt.Signature) + if reporter != nil { + reporter(pt.Signature) } return false } - } else if !b.pseudoTypeEquivalentToType(pt.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, reportErrors) { + } else if !b.pseudoTypeEquivalentToType(pt.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, reporter) { // error reported within the return type return false } return true case pseudochecker.PseudoTypeKindNoResult: - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(t.AsPseudoTypeNoResult().Declaration) + if reporter != nil { + if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + reporter(n) + } + } else { + reporter(t.AsPseudoTypeNoResult().Declaration) + } } return false case pseudochecker.PseudoTypeKindInferred: - if reportErrors { - b.ctx.tracker.ReportInferenceFallback(t.AsPseudoTypeInferred().Expression) + if reporter != nil { + if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + reporter(n) + } + } else { + reporter(t.AsPseudoTypeInferred().Expression) + } } return false default: @@ -511,6 +556,16 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } } +func isStructuralPseudoType(t *pseudochecker.PseudoType) bool { + switch t.Kind { + case pseudochecker.PseudoTypeKindObjectLiteral, pseudochecker.PseudoTypeKindTuple, pseudochecker.PseudoTypeKindSingleCallSignature: + return true + case pseudochecker.PseudoTypeKindMaybeConstLocation: + return isStructuralPseudoType(t.AsPseudoTypeMaybeConstLocation().ConstType) || isStructuralPseudoType(t.AsPseudoTypeMaybeConstLocation().RegularType) + } + return false +} + // pseudoReturnTypeMatchesPredicate checks if a pseudo return type (which should be a Direct type // wrapping a TypePredicateNode) matches the given type predicate from the checker. func (b *NodeBuilderImpl) pseudoReturnTypeMatchesPredicate(rt *pseudochecker.PseudoType, predicate *TypePredicate) bool { diff --git a/internal/pseudochecker/lookup.go b/internal/pseudochecker/lookup.go index 6684a423204..e1d3b7618e6 100644 --- a/internal/pseudochecker/lookup.go +++ b/internal/pseudochecker/lookup.go @@ -88,7 +88,8 @@ func (ch *PseudoChecker) typeFromPropertyAssignment(node *ast.Node) *PseudoType if expr != nil && expr.Kind != PseudoTypeKindInferred { return expr } - // fallback to NoResult if PseudoTypeKindInferred + // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes + return NewPseudoTypeNoResultFromInferred(node, expr) } } return NewPseudoTypeNoResult(node) @@ -125,7 +126,8 @@ func (ch *PseudoChecker) typeFromProperty(node *ast.Node) *PseudoType { } return expr } - // fallback to NoResult if PseudoTypeKindInferred + // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes + return NewPseudoTypeNoResultFromInferred(node, expr) } } return NewPseudoTypeNoResult(node) @@ -147,7 +149,8 @@ func (ch *PseudoChecker) typeFromVariable(declaration *ast.VariableDeclaration) if expr != nil && expr.Kind != PseudoTypeKindInferred { return expr } - // fallback to NoResult if PseudoTypeKindInferred + // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes + return NewPseudoTypeNoResultFromInferred(declaration.AsNode(), expr) } } return NewPseudoTypeNoResult(declaration.AsNode()) @@ -322,8 +325,8 @@ func (ch *PseudoChecker) typeFromExpression(node *ast.Node) *PseudoType { } func (ch *PseudoChecker) typeFromObjectLiteral(node *ast.ObjectLiteralExpression) *PseudoType { - if !ch.canGetTypeFromObjectLiteral(node) { - return NewPseudoTypeInferred(node.AsNode()) + if errorNodes := ch.canGetTypeFromObjectLiteral(node); errorNodes != nil { + return NewPseudoTypeInferredWithErrors(node.AsNode(), errorNodes) } // we are in a const context producing an object literal type, there are no shorthand or spread assignments if node.Properties == nil || len(node.Properties.Nodes) == 0 { @@ -409,41 +412,45 @@ func (ch *PseudoChecker) getAccessorMember(accessor *ast.Node, name *ast.Node) * return nil } -func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpression) bool { +// canGetTypeFromObjectLiteral checks whether an object literal can be typed by the pseudochecker. +// Returns nil if the object can be typed, or a slice of error nodes (shorthand/spread properties, +// non-literal computed names) that prevent typing. +func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpression) []*ast.Node { if node.Properties == nil || len(node.Properties.Nodes) == 0 { - return true // empty object + return nil // empty object, ok } - // !!! TODO: strada reports errors on multiple non-inferrable props - // via calling reportInferenceFallback multiple times here before returning. - // Does that logic need to be included in this checker? Or can it - // be kept to the `PseudoType` -> `Node` mapping logic, so this - // checker can avoid needing any error reporting logic? + var errorNodes []*ast.Node for _, e := range node.Properties.Nodes { if e.Flags&ast.NodeFlagsThisNodeHasError != 0 { - return false + // Return empty (non-nil) slice to signal failure without specific error nodes + return []*ast.Node{} } if e.Kind == ast.KindShorthandPropertyAssignment || e.Kind == ast.KindSpreadAssignment { - return false + errorNodes = append(errorNodes, e) + continue } if e.Name().Flags&ast.NodeFlagsThisNodeHasError != 0 { - return false + return []*ast.Node{} } if e.Name().Kind == ast.KindPrivateIdentifier { - return false + if errorNodes == nil { + errorNodes = []*ast.Node{} // signal failure + } + continue } if e.Name().Kind == ast.KindComputedPropertyName { expression := e.Name().Expression() if !ast.IsPrimitiveLiteralValue(expression, false) { - return false + errorNodes = append(errorNodes, e.Name()) } } } - return true + return errorNodes } func (ch *PseudoChecker) typeFromArrayLiteral(node *ast.ArrayLiteralExpression) *PseudoType { - if !ch.canGetTypeFromArrayLiteral(node) { - return NewPseudoTypeInferred(node.AsNode()) + if errorNodes := ch.canGetTypeFromArrayLiteral(node); errorNodes != nil { + return NewPseudoTypeInferredWithErrors(node.AsNode(), errorNodes) } if IsInConstContext(node.AsNode()) && isContextuallyTyped(node.AsNode()) { return NewPseudoTypeInferred(node.AsNode()) // expr in an as const cast with a contextual type has variable readonly state, bail @@ -456,16 +463,20 @@ func (ch *PseudoChecker) typeFromArrayLiteral(node *ast.ArrayLiteralExpression) return NewPseudoTypeTuple(results) } -func (ch *PseudoChecker) canGetTypeFromArrayLiteral(node *ast.ArrayLiteralExpression) bool { +// canGetTypeFromArrayLiteral checks whether an array literal can be typed by the pseudochecker. +// Returns nil if the array can be typed, or a slice of error nodes that prevent typing. +// For non-const arrays, the error node is the array expression itself. +// For const arrays with spreads, the error node is the spread element. +func (ch *PseudoChecker) canGetTypeFromArrayLiteral(node *ast.ArrayLiteralExpression) []*ast.Node { if !IsInConstContext(node.AsNode()) { - return false + return []*ast.Node{node.AsNode()} } for _, e := range node.Elements.Nodes { if e.Kind == ast.KindSpreadElement { - return false + return []*ast.Node{e} } } - return true + return nil } // See `isConstContext` in `checker.go` - this is basically any node kind mentioned in that diff --git a/internal/pseudochecker/type.go b/internal/pseudochecker/type.go index e4e70e25af0..ab8f6d40f0f 100644 --- a/internal/pseudochecker/type.go +++ b/internal/pseudochecker/type.go @@ -42,10 +42,15 @@ const ( ) type PseudoType struct { - Kind PseudoTypeKind - data pseudoTypeData + Kind PseudoTypeKind + errorNodes []*ast.Node + data pseudoTypeData } +// ErrorNodes returns the specific child nodes that caused an inference failure, +// collected during pseudochecker construction. Nil/empty means no specific children. +func (t *PseudoType) ErrorNodes() []*ast.Node { return t.errorNodes } + func newPseudoType(kind PseudoTypeKind, data pseudoTypeData) *PseudoType { n := data.AsPseudoType() n.Kind = kind @@ -53,6 +58,12 @@ func newPseudoType(kind PseudoTypeKind, data pseudoTypeData) *PseudoType { return n } +func newPseudoTypeWithErrors(kind PseudoTypeKind, data pseudoTypeData, errorNodes []*ast.Node) *PseudoType { + n := newPseudoType(kind, data) + n.errorNodes = errorNodes + return n +} + type pseudoTypeData interface { AsPseudoType() *PseudoType } @@ -94,6 +105,8 @@ func (t *PseudoType) AsPseudoTypeDirect() *PseudoTypeDirect { return t.data.(*Ps // PseudoTypeInferred directly encodes the type referred to by a given Expression // These represent cases where the expression was too complex for the pseudochecker. // Most of the time, these locations will produce an error under ID. +// Specific error nodes (shorthand properties, spread assignments, etc.) are stored on the +// PseudoType.errorNodes field, collected during pseudochecker construction. type PseudoTypeInferred struct { PseudoTypeBase Expression *ast.Node @@ -103,9 +116,13 @@ func NewPseudoTypeInferred(expr *ast.Node) *PseudoType { return newPseudoType(PseudoTypeKindInferred, &PseudoTypeInferred{Expression: expr}) } +func NewPseudoTypeInferredWithErrors(expr *ast.Node, errorNodes []*ast.Node) *PseudoType { + return newPseudoTypeWithErrors(PseudoTypeKindInferred, &PseudoTypeInferred{Expression: expr}, errorNodes) +} + func (t *PseudoType) AsPseudoTypeInferred() *PseudoTypeInferred { return t.data.(*PseudoTypeInferred) } -// PseudoTypeNoResult is anlogous to PseudoTypeInferred in that it references a case +// PseudoTypeNoResult is analogous to PseudoTypeInferred in that it references a case // where the type was too complex for the pseudochecker. Rather than an expression, however, // it is referring to the return type of a signature or declaration. type PseudoTypeNoResult struct { @@ -117,6 +134,15 @@ func NewPseudoTypeNoResult(decl *ast.Node) *PseudoType { return newPseudoType(PseudoTypeKindNoResult, &PseudoTypeNoResult{Declaration: decl}) } +// NewPseudoTypeNoResultFromInferred collapses a PseudoTypeInferred into a PseudoTypeNoResult +// for the given declaration, preserving any ErrorNodes from the inferred type. +func NewPseudoTypeNoResultFromInferred(decl *ast.Node, inferred *PseudoType) *PseudoType { + if inferred != nil && len(inferred.ErrorNodes()) > 0 { + return newPseudoTypeWithErrors(PseudoTypeKindNoResult, &PseudoTypeNoResult{Declaration: decl}, inferred.ErrorNodes()) + } + return NewPseudoTypeNoResult(decl) +} + func (t *PseudoType) AsPseudoTypeNoResult() *PseudoTypeNoResult { return t.data.(*PseudoTypeNoResult) } // PseudoTypeMaybeConstLocation encodes the const/regular types of a location so the builder diff --git a/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt b/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt index 317bd46e115..f4aae6aa04d 100644 --- a/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt @@ -1,12 +1,12 @@ -computedPropertiesNarrowed.ts(4,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(10,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(18,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(21,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(25,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(30,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(36,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(41,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -computedPropertiesNarrowed.ts(46,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +computedPropertiesNarrowed.ts(5,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(18,20): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(22,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(26,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(31,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(37,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(42,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. ==== computedPropertiesNarrowed.ts (9 errors) ==== @@ -14,19 +14,19 @@ computedPropertiesNarrowed.ts(46,14): error TS9010: Variable must have an explic declare function assert(n: number): asserts n is 1; assert(x); export let o = { - ~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:4:12: Add a type annotation to the variable o. [x]: 1 // error narrow type !== declared type + ~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:4:12: Add a type annotation to the variable o. } const y: 0 = 0 export let o2 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:10:12: Add a type annotation to the variable o2. [y]: 1 // ok literal computed type + ~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:10:12: Add a type annotation to the variable o2. } // literals are ok @@ -34,55 +34,55 @@ computedPropertiesNarrowed.ts(46,14): error TS9010: Variable must have an explic export let o31 = { [-1]: 1 } export let o32 = { [1-1]: 1 } // error number - ~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. + ~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. !!! related TS9027 computedPropertiesNarrowed.ts:18:12: Add a type annotation to the variable o32. let u = Symbol(); export let o4 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:21:12: Add a type annotation to the variable o4. [u]: 1 // Should error, nut a unique symbol + ~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:21:12: Add a type annotation to the variable o4. } export let o5 ={ - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:25:12: Add a type annotation to the variable o5. [Symbol()]: 1 // Should error + ~~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:25:12: Add a type annotation to the variable o5. } const uu: unique symbol = Symbol(); export let o6 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:30:12: Add a type annotation to the variable o6. [uu]: 1 // Should be ok + ~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:30:12: Add a type annotation to the variable o6. } function foo (): 1 { return 1; } export let o7 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:36:12: Add a type annotation to the variable o7. [foo()]: 1 // Should error + ~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:36:12: Add a type annotation to the variable o7. }; let E = { A: 1 } as const export const o8 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:41:14: Add a type annotation to the variable o8. [E.A]: 1 // Fresh + ~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:41:14: Add a type annotation to the variable o8. } function ns() { return { v: 0 } as const } export const o9 = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:46:14: Add a type annotation to the variable o9. [ns().v]: 1 + ~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:46:14: Add a type annotation to the variable o9. } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt.diff index 9655452d5a2..182799637a9 100644 --- a/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.errors.txt.diff @@ -1,65 +1,23 @@ --- old.computedPropertiesNarrowed.errors.txt +++ new.computedPropertiesNarrowed.errors.txt @@= skipped -0, +0 lines =@@ --computedPropertiesNarrowed.ts(5,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(18,20): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + computedPropertiesNarrowed.ts(5,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + computedPropertiesNarrowed.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + computedPropertiesNarrowed.ts(18,20): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -computedPropertiesNarrowed.ts(20,5): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. --computedPropertiesNarrowed.ts(22,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(26,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(31,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(37,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(42,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -- -- + computedPropertiesNarrowed.ts(22,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + computedPropertiesNarrowed.ts(26,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + computedPropertiesNarrowed.ts(31,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +@@= skipped -9, +8 lines =@@ + computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + + -==== computedPropertiesNarrowed.ts (10 errors) ==== -+computedPropertiesNarrowed.ts(4,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(10,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(18,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(21,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(25,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(30,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(36,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(41,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+computedPropertiesNarrowed.ts(46,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+ -+ +==== computedPropertiesNarrowed.ts (9 errors) ==== const x: 0 | 1 = Math.random()? 0: 1; declare function assert(n: number): asserts n is 1; assert(x); - export let o = { -- [x]: 1 // error narrow type !== declared type -- ~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:4:12: Add a type annotation to the variable o. -+ [x]: 1 // error narrow type !== declared type - } - - - const y: 0 = 0 - export let o2 = { -- [y]: 1 // ok literal computed type -- ~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:10:12: Add a type annotation to the variable o2. -+ [y]: 1 // ok literal computed type - } - - // literals are ok -@@= skipped -34, +33 lines =@@ - export let o31 = { [-1]: 1 } - - export let o32 = { [1-1]: 1 } // error number -- ~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +@@= skipped -30, +30 lines =@@ !!! related TS9027 computedPropertiesNarrowed.ts:18:12: Add a type annotation to the variable o32. let u = Symbol(); @@ -67,67 +25,5 @@ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 computedPropertiesNarrowed.ts:20:5: Add a type annotation to the variable u. export let o4 = { -- [u]: 1 // Should error, nut a unique symbol -- ~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:21:12: Add a type annotation to the variable o4. -+ [u]: 1 // Should error, nut a unique symbol - } - - export let o5 ={ -- [Symbol()]: 1 // Should error -- ~~~~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:25:12: Add a type annotation to the variable o5. -+ [Symbol()]: 1 // Should error - } - - const uu: unique symbol = Symbol(); - export let o6 = { -- [uu]: 1 // Should be ok -- ~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:30:12: Add a type annotation to the variable o6. -+ [uu]: 1 // Should be ok - } - - - function foo (): 1 { return 1; } - export let o7 = { -- [foo()]: 1 // Should error -- ~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:36:12: Add a type annotation to the variable o7. -+ [foo()]: 1 // Should error - }; - - let E = { A: 1 } as const - export const o8 = { -- [E.A]: 1 // Fresh -- ~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:41:14: Add a type annotation to the variable o8. -+ [E.A]: 1 // Fresh - } - - function ns() { return { v: 0 } as const } - export const o9 = { -- [ns().v]: 1 -- ~~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 computedPropertiesNarrowed.ts:46:14: Add a type annotation to the variable o9. -+ [ns().v]: 1 - } - \ No newline at end of file + [u]: 1 // Should error, nut a unique symbol + ~~~ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt index 65a5f6b97e3..3c234b8c804 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt @@ -19,8 +19,8 @@ isolatedDeclarationErrorsExpressions.ts(33,12): error TS9010: Variable must have isolatedDeclarationErrorsExpressions.ts(49,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(50,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(51,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsExpressions.ts(53,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsExpressions.ts(55,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(53,18): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(55,38): error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(59,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(60,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(61,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. @@ -169,13 +169,13 @@ isolatedDeclarationErrorsExpressions.ts(128,19): error TS9019: Binding elements !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:51:12: Add a type annotation to the variable templateLetOk4AsConst. export let arr = [1, 2, 3]; - ~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. + ~~~~~~~~~ +!!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:53:12: Add a type annotation to the variable arr. export let arrConst = [1, 2, 3] as const; export let arrWithSpread = [1, 2, 3, ...arr] as const; - ~~~~~~~~~~~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. + ~~~~~~ +!!! error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:55:12: Add a type annotation to the variable arrWithSpread. export class Exported { diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt.diff index da8ac97dc63..f79203b048b 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.errors.txt.diff @@ -1,17 +1,6 @@ --- old.isolatedDeclarationErrorsExpressions.errors.txt +++ new.isolatedDeclarationErrorsExpressions.errors.txt -@@= skipped -18, +18 lines =@@ - isolatedDeclarationErrorsExpressions.ts(49,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsExpressions.ts(50,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsExpressions.ts(51,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. --isolatedDeclarationErrorsExpressions.ts(53,18): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsExpressions.ts(55,38): error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsExpressions.ts(53,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+isolatedDeclarationErrorsExpressions.ts(55,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsExpressions.ts(59,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsExpressions.ts(60,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsExpressions.ts(61,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. -@@= skipped -24, +24 lines =@@ +@@= skipped -42, +42 lines =@@ isolatedDeclarationErrorsExpressions.ts(104,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(109,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(110,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. @@ -24,25 +13,7 @@ isolatedDeclarationErrorsExpressions.ts(119,36): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(127,16): error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. isolatedDeclarationErrorsExpressions.ts(128,19): error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. -@@= skipped -126, +126 lines =@@ - !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:51:12: Add a type annotation to the variable templateLetOk4AsConst. - - export let arr = [1, 2, 3]; -- ~~~~~~~~~ --!!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. -+ ~~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:53:12: Add a type annotation to the variable arr. - export let arrConst = [1, 2, 3] as const; - export let arrWithSpread = [1, 2, 3, ...arr] as const; -- ~~~~~~ --!!! error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. -+ ~~~~~~~~~~~~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsExpressions.ts:55:12: Add a type annotation to the variable arrWithSpread. - - export class Exported { -@@= skipped -131, +131 lines =@@ +@@= skipped -257, +257 lines =@@ !!! related TS9028 isolatedDeclarationErrorsExpressions.ts:110:33: Add a type annotation to the parameter p. export function numberParamBad3(p = numberParam): void { } ~~~~~~~~~~~ diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt index 4136c28c66d..8fa23907bd2 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt @@ -1,23 +1,25 @@ isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. isolatedDeclarationErrorsObjects.ts(40,25): error TS7006: Parameter 'value' implicitly has an 'any' type. isolatedDeclarationErrorsObjects.ts(40,25): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(62,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(73,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(64,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(65,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(66,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(67,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(68,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(75,5): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(77,5): error TS9016: Objects that contain shorthand properties can't be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -==== isolatedDeclarationErrorsObjects.ts (17 errors) ==== +==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== export let o = { a: 1, b: "" @@ -40,20 +42,13 @@ isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. }, c: { - ~ d: 1, - ~~~~~~~~~~~~~ e: V, - ~~~~~~~~~~~~~ ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } export let oWithMethods = { @@ -77,28 +72,19 @@ isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't } export let oWithMethodsNested = { foo: { - ~ method() { }, - ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method a: 1, - ~~~~~~~~~~~~~ okMethod(): void { }, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bad() { } - ~~~~~~~~~~~~~~~~~ ~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method } - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } @@ -135,25 +121,37 @@ isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't V = 10, } export const oWithComputedProperties = { - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. [1]: 1, [1 + 3]: 1, + ~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. [prop(2)]: 2, + ~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. [s]: 1, + ~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. [E.V]: 1, + ~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. [str]: 0, + ~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. } const part = { a: 1 }; export const oWithSpread = { - ~~~~~~~~~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. b: 1, ...part, + ~~~~~~~ +!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. c: 1, part, ~~~~ @@ -165,14 +163,11 @@ isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't export const oWithSpread2 = { b: 1, nested: { - ~ ...part, - ~~~~~~~~~~~~~~~~ - }, - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~ +!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:81:14: Add a type annotation to the variable oWithSpread2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:83:13: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + }, c: 1, } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff deleted file mode 100644 index 21d8bfee4b0..00000000000 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff +++ /dev/null @@ -1,148 +0,0 @@ ---- old.isolatedDeclarationErrorsObjects.errors.txt -+++ new.isolatedDeclarationErrorsObjects.errors.txt -@@= skipped -0, +0 lines =@@ - isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. - isolatedDeclarationErrorsObjects.ts(40,25): error TS7006: Parameter 'value' implicitly has an 'any' type. - isolatedDeclarationErrorsObjects.ts(40,25): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(64,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(65,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(66,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(67,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(68,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(75,5): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(62,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(73,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(77,5): error TS9016: Objects that contain shorthand properties can't be inferred with --isolatedDeclarations. --isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -- -- --==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== -+isolatedDeclarationErrorsObjects.ts(83,13): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+ -+ -+==== isolatedDeclarationErrorsObjects.ts (17 errors) ==== - export let o = { - a: 1, - b: "" -@@= skipped -41, +39 lines =@@ - !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - }, - c: { -+ ~ - d: 1, -+ ~~~~~~~~~~~~~ - e: V, -+ ~~~~~~~~~~~~~ - ~ - !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. - !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -+!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } - - export let oWithMethods = { -@@= skipped -30, +37 lines =@@ - } - export let oWithMethodsNested = { - foo: { -+ ~ - method() { }, -+ ~~~~~~~~~~~~~~~~~~~~~ - ~~~~~~ - !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. - !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method - a: 1, -+ ~~~~~~~~~~~~~ - okMethod(): void { }, -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - bad() { } -+ ~~~~~~~~~~~~~~~~~ - ~~~ - !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. - !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method - } -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. -+!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } - - -@@= skipped -49, +58 lines =@@ - V = 10, - } - export const oWithComputedProperties = { -+ ~~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - [1]: 1, - [1 + 3]: 1, -- ~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - [prop(2)]: 2, -- ~~~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - [s]: 1, -- ~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - [E.V]: 1, -- ~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - [str]: 0, -- ~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. - } - - const part = { a: 1 }; - - export const oWithSpread = { -+ ~~~~~~~~~~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. - b: 1, - ...part, -- ~~~~~~~ --!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. - c: 1, - part, - ~~~~ -@@= skipped -42, +30 lines =@@ - export const oWithSpread2 = { - b: 1, - nested: { -+ ~ - ...part, -- ~~~~~~~ --!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -+ ~~~~~~~~~~~~~~~~ -+ }, -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:81:14: Add a type annotation to the variable oWithSpread2. -- }, -+!!! related TS9035 isolatedDeclarationErrorsObjects.ts:83:13: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - c: 1, - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt index 1d718f8a1f8..812ec2c1bea 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt @@ -2,10 +2,11 @@ isolatedDeclarationLazySymbols.ts(1,17): error TS9007: Function must have an exp isolatedDeclarationLazySymbols.ts(13,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. isolatedDeclarationLazySymbols.ts(16,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. isolatedDeclarationLazySymbols.ts(16,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -isolatedDeclarationLazySymbols.ts(20,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationLazySymbols.ts(21,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationLazySymbols.ts(22,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -==== isolatedDeclarationLazySymbols.ts (5 errors) ==== +==== isolatedDeclarationLazySymbols.ts (6 errors) ==== export function foo() { ~~~ !!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. @@ -35,9 +36,12 @@ isolatedDeclarationLazySymbols.ts(20,12): error TS9010: Variable must have an ex } export let oo = { - ~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. [o['prop.inner']]:"A", + ~~~~~~~~~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. [o.prop.inner]: "B", + ~~~~~~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt.diff deleted file mode 100644 index b8d25a00a27..00000000000 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationLazySymbols.errors.txt.diff +++ /dev/null @@ -1,34 +0,0 @@ ---- old.isolatedDeclarationLazySymbols.errors.txt -+++ new.isolatedDeclarationLazySymbols.errors.txt -@@= skipped -1, +1 lines =@@ - isolatedDeclarationLazySymbols.ts(13,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. - isolatedDeclarationLazySymbols.ts(16,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. - isolatedDeclarationLazySymbols.ts(16,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationLazySymbols.ts(21,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --isolatedDeclarationLazySymbols.ts(22,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -- -- --==== isolatedDeclarationLazySymbols.ts (6 errors) ==== -+isolatedDeclarationLazySymbols.ts(20,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+ -+ -+==== isolatedDeclarationLazySymbols.ts (5 errors) ==== - export function foo() { - ~~~ - !!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. -@@= skipped -34, +33 lines =@@ - } - - export let oo = { -+ ~~ -+!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. - [o['prop.inner']]:"A", -- ~~~~~~~~~~~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. - [o.prop.inner]: "B", -- ~~~~~~~~~~~~~~ --!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. --!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. - } \ No newline at end of file From 8c48ca82bf4b24729069e9973c6cc10b58bccd76 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 26 Mar 2026 19:32:17 -0700 Subject: [PATCH 2/5] more --- internal/checker/nodebuilderimpl.go | 23 +-- internal/checker/pseudotypenodebuilder.go | 174 ++++++++---------- internal/pseudochecker/lookup.go | 15 +- internal/pseudochecker/type.go | 9 - .../conditionalTypeDoesntSpinForever.types | 30 +-- ...onditionalTypeDoesntSpinForever.types.diff | 93 ---------- ...solatedDeclarationErrorsDefault.errors.txt | 7 +- ...edDeclarationErrorsDefault.errors.txt.diff | 27 --- ...solatedDeclarationErrorsObjects.errors.txt | 20 +- ...edDeclarationErrorsObjects.errors.txt.diff | 73 ++++++++ .../jsDeclarationsJson(target=es2015).js | 6 +- .../jsDeclarationsJson(target=es2015).js.diff | 15 +- .../jsDeclarationsJson(target=es2015).types | 14 +- ...DeclarationsJson(target=es2015).types.diff | 29 ++- 14 files changed, 244 insertions(+), 291 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt.diff create mode 100644 testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff diff --git a/internal/checker/nodebuilderimpl.go b/internal/checker/nodebuilderimpl.go index 4830e86fe0e..23886e4e8f0 100644 --- a/internal/checker/nodebuilderimpl.go +++ b/internal/checker/nodebuilderimpl.go @@ -134,17 +134,6 @@ func (b *NodeBuilderImpl) saveRestoreFlags() func() { } } -// inferenceFallbackReporter returns a reporter func for use with pseudoTypeEquivalentToType. -// Returns nil when inference fallback reporting is suppressed, otherwise returns the tracker's -// ReportInferenceFallback. Error nodes for object/array literal children are already stored in -// PseudoTypeInferred.ErrorNodes during pseudochecker construction and reported inline. -func (b *NodeBuilderImpl) inferenceFallbackReporter() func(*ast.Node) { - if b.ctx.suppressReportInferenceFallback { - return nil - } - return b.ctx.tracker.ReportInferenceFallback -} - func (b *NodeBuilderImpl) checkTruncationLength() bool { if b.ctx.truncating { return b.ctx.truncating @@ -1988,7 +1977,7 @@ func (b *NodeBuilderImpl) serializeReturnTypeForSignature(signature *Signature, declarationSymbol := b.ch.getSymbolOfDeclaration(signature.declaration) restore := b.addSymbolTypeToContext(declarationSymbol, returnType) pt := b.pc.GetReturnTypeOfSignature(signature.declaration) - if b.pseudoTypeEquivalentToType(pt, returnType, false, b.inferenceFallbackReporter()) { + if b.pseudoTypeEquivalentToType(pt, returnType, false, !b.ctx.suppressReportInferenceFallback) { // Also verify the pseudo type captures any inferred type predicate, not just the boolean return type. // The pseudochecker is unaware of inferred type predicates, so it produces boolean where // the checker infers e.g. `x is string`. @@ -2002,7 +1991,7 @@ func (b *NodeBuilderImpl) serializeReturnTypeForSignature(signature *Signature, if pt != nil { // !!! TODO: If annotated type node is a reference with insufficient type arguments, we should still fall back to type serialization // see: canReuseTypeNodeAnnotation in strada for context - returnTypeNode = b.pseudoTypeToNode(pt) + returnTypeNode = b.pseudoTypeToNodeWithCheckerFallback(pt, returnType) } } restore() @@ -2099,18 +2088,18 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati } else { pt = b.pc.GetTypeOfDeclaration(declaration) } - if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameter(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), b.inferenceFallbackReporter()) { + if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameter(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), !b.ctx.suppressReportInferenceFallback) { // !!! TODO: If annotated type node is a reference with insufficient type arguments, we should still fall back to type serialization // see: canReuseTypeNodeAnnotation in strada for context ptt := b.pseudoTypeToType(pt) if ptt != nil && requiresAddingUndefined && containsNonMissingUndefinedType(b.ch, t) && !containsNonMissingUndefinedType(b.ch, ptt) { pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined}) } - result = b.pseudoTypeToNode(pt) + result = b.pseudoTypeToNodeWithCheckerFallback(pt, t) } else if requiresAddingUndefined { pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined}) - if b.pseudoTypeEquivalentToType(pt, t, false, b.inferenceFallbackReporter()) { - result = b.pseudoTypeToNode(pt) + if b.pseudoTypeEquivalentToType(pt, t, false, !b.ctx.suppressReportInferenceFallback) { + result = b.pseudoTypeToNodeWithCheckerFallback(pt, t) } } remove() diff --git a/internal/checker/pseudotypenodebuilder.go b/internal/checker/pseudotypenodebuilder.go index f24585b2f4d..e0fc358bb84 100644 --- a/internal/checker/pseudotypenodebuilder.go +++ b/internal/checker/pseudotypenodebuilder.go @@ -8,6 +8,30 @@ import ( "github.com/microsoft/typescript-go/internal/pseudochecker" ) +// pseudoTypeToNodeWithCheckerFallback is like pseudoTypeToNode but when the top-level pseudo type +// is PseudoTypeInferred, it reports any error nodes and then serializes from the checker's type. +// This avoids incorrect type output when PseudoTypeInferred would derive the type from the +// original declaration expression in an instantiated context. +func (b *NodeBuilderImpl) pseudoTypeToNodeWithCheckerFallback(t *pseudochecker.PseudoType, checkerType *Type) *ast.Node { + if t.Kind == pseudochecker.PseudoTypeKindInferred { + if !b.ctx.suppressReportInferenceFallback { + if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + for _, n := range errorNodes { + b.ctx.tracker.ReportInferenceFallback(n) + } + } else { + b.ctx.tracker.ReportInferenceFallback(t.AsPseudoTypeInferred().Expression) + } + } + oldSuppress := b.ctx.suppressReportInferenceFallback + b.ctx.suppressReportInferenceFallback = true + result := b.typeToTypeNode(checkerType) + b.ctx.suppressReportInferenceFallback = oldSuppress + return result + } + return b.pseudoTypeToNode(t) +} + // Maps a pseudochecker's pseudotypes into ast nodes and reports any inference fallback errors the pseudotype structure implies func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Node { debug.Assert(t != nil, "Attempted to serialize nil pseudotype") @@ -15,11 +39,14 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod case pseudochecker.PseudoTypeKindDirect: return b.reuseTypeNode(t.AsPseudoTypeDirect().TypeNode) case pseudochecker.PseudoTypeKindInferred: - node := t.AsPseudoTypeInferred().Expression + inferred := t.AsPseudoTypeInferred() + node := inferred.Expression if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { for _, n := range errorNodes { b.ctx.tracker.ReportInferenceFallback(n) } + } else if ast.IsEntityNameExpression(node) && ast.IsDeclaration(node.Parent) { + b.ctx.tracker.ReportInferenceFallback(node.Parent) } else { b.ctx.tracker.ReportInferenceFallback(node) } @@ -42,13 +69,7 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod return b.typeToTypeNode(ty) case pseudochecker.PseudoTypeKindNoResult: node := t.AsPseudoTypeNoResult().Declaration - if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { - for _, n := range errorNodes { - b.ctx.tracker.ReportInferenceFallback(n) - } - } else { - b.ctx.tracker.ReportInferenceFallback(node) - } + b.ctx.tracker.ReportInferenceFallback(node) if ast.IsFunctionLike(node) && !ast.IsAccessor(node) { return b.serializeReturnTypeForSignature(b.ch.getSignatureFromDeclaration(node), false) } @@ -165,12 +186,6 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod isConst := b.ch.isConstContext(elements[0].Name) newElements := make([]*ast.Node, 0, len(elements)) - // Suppress inference fallback reporting during object literal element construction. - // Errors on failing elements are already reported during the comparison phase via ErrorNodes; - // this matches strada's noInferenceFallback = true during nested construction. - oldSuppressReportInferenceFallback := b.ctx.suppressReportInferenceFallback - b.ctx.suppressReportInferenceFallback = true - for _, e := range elements { var modifiers *ast.ModifierList if isConst || (e.Kind == pseudochecker.PseudoObjectElementKindPropertyAssignment && e.AsPseudoPropertyAssignment().Readonly) { @@ -253,7 +268,6 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod } newElements = append(newElements, newProp) } - b.ctx.suppressReportInferenceFallback = oldSuppressReportInferenceFallback result := b.f.NewTypeLiteralNode(b.f.NewNodeList(newElements)) if b.ctx.flags&nodebuilder.FlagsMultilineObjectLiterals == 0 { b.e.AddEmitFlags(result, printer.EFSingleLine) @@ -299,10 +313,7 @@ func (b *NodeBuilderImpl) pseudoParameterToNode(p *pseudochecker.PseudoParameter // see `typeNodeIsEquivalentToType` in strada, but applied more broadly here, so is setup to handle more equivalences - strada only used it via // the `canReuseTypeNodeAnnotation` host hook and not the `canReuseTypeNode` hook, which meant locations using the later were reliant on // over-invalidation by the ID inference engine to not emit incorrect types. -// reporter, when non-nil, is called on failure with the node to report the error on. For structural types -// like ObjectLiteral, per-element reporters are created that bind to each property's declaration, so errors -// propagate to the innermost failing leaf rather than firing on intermediate structural containers. -func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType, type_ *Type, isOptionalAnnotated bool, reporter func(*ast.Node)) bool { +func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType, type_ *Type, isOptionalAnnotated bool, reportErrors bool) bool { // if type_ resolves to an error, we charitably assume equality, since we might be in a single-file checking mode if type_ != nil && b.ch.isErrorType(type_) { return true @@ -338,6 +349,17 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } // otherwise, fallback to actual pseudo/type cross-comparisons switch t.Kind { + case pseudochecker.PseudoTypeKindInferred: + // PseudoTypeInferred with error nodes is always considered equivalent — + // the error nodes identify specific problematic children, and pseudoTypeToNodeWithCheckerFallback + // will report errors on them and fall back to the checker's real type. + if len(t.ErrorNodes()) > 0 { + return true + } + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(t.AsPseudoTypeInferred().Expression) + } + return false case pseudochecker.PseudoTypeKindObjectLiteral: pt := t.AsPseudoTypeObjectLiteral() if type_ == nil { @@ -369,16 +391,16 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } } if targetProp == nil { - if reporter != nil { - reporter(e.Name.Parent) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } } targetIsOptional := targetProp.Flags&ast.SymbolFlagsOptional != 0 if e.Optional != targetIsOptional { - if reporter != nil { - reporter(e.Name.Parent) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } @@ -387,20 +409,9 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType switch e.Kind { case pseudochecker.PseudoObjectElementKindPropertyAssignment: d := e.AsPseudoPropertyAssignment() - if !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, nil) { - if reporter != nil { - // If the property's type has specific error nodes from construction - // (e.g. spread, shorthand, computed names), report on those. - // For structural types (ObjectLiteral/Tuple/Signature), don't report - // here — the outer fallback to checker-based serialization handles them. - // Otherwise report on the property itself. - if errorNodes := d.Type.ErrorNodes(); len(errorNodes) > 0 { - for _, n := range errorNodes { - reporter(n) - } - } else if !isStructuralPseudoType(d.Type) { - reporter(e.Name.Parent) - } + if !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } @@ -412,17 +423,17 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType continue } if len(targetSig.parameters) != len(d.Parameters) { - if reporter != nil { - reporter(e.Name.Parent) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } for i, p := range d.Parameters { targetParam := targetSig.parameters[i] paramType := b.ch.getTypeOfParameter(targetParam) - if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, nil) { - if reporter != nil { - reporter(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } @@ -430,31 +441,31 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType targetPredicate := b.ch.getTypePredicateOfSignature(targetSig) if targetPredicate != nil { if !b.pseudoReturnTypeMatchesPredicate(d.ReturnType, targetPredicate) { - if reporter != nil { - reporter(e.Name.Parent) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } - } else if !b.pseudoTypeEquivalentToType(d.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, nil) { - if reporter != nil { - reporter(e.Name.Parent) + } else if !b.pseudoTypeEquivalentToType(d.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } case pseudochecker.PseudoObjectElementKindGetAccessor: d := e.AsPseudoGetAccessor() - if !b.pseudoTypeEquivalentToType(d.Type, propType, false, nil) { - if reporter != nil { - reporter(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(d.Type, propType, false, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } case pseudochecker.PseudoObjectElementKindSetAccessor: d := e.AsPseudoSetAccessor() writeType := b.ch.getWriteTypeOfSymbol(targetProp) - if !b.pseudoTypeEquivalentToType(d.Parameter.Type, writeType, false, nil) { - if reporter != nil { - reporter(e.Name.Parent) + if !b.pseudoTypeEquivalentToType(d.Parameter.Type, writeType, false, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false } @@ -477,7 +488,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType return false } for i, elem := range pt.Elements { - if !b.pseudoTypeEquivalentToType(elem, elementTypes[i], false, reporter) { + if !b.pseudoTypeEquivalentToType(elem, elementTypes[i], false, reportErrors) { return false } } @@ -489,29 +500,29 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } pt := t.AsPseudoTypeSingleCallSignature() if len(targetSig.typeParameters) != len(pt.TypeParameters) { - if reporter != nil { - reporter(pt.Signature) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(pt.Signature) } return false } if len(targetSig.parameters) != len(pt.Parameters) { - if reporter != nil { - reporter(pt.Signature) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(pt.Signature) } return false // TODO: spread tuple params may mess with this check } for i, p := range pt.Parameters { targetParam := targetSig.parameters[i] if p.Optional != b.ch.isOptionalParameter(targetParam.ValueDeclaration) { - if reporter != nil { - reporter(p.Name.Parent) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(p.Name.Parent) } return false } paramType := b.ch.getTypeOfParameter(targetParam) - if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, nil) { - if reporter != nil { - reporter(p.Name.Parent) + if !b.pseudoTypeEquivalentToType(p.Type, paramType, p.Optional, false) { + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(p.Name.Parent) } return false } @@ -519,36 +530,19 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType targetPredicate := b.ch.getTypePredicateOfSignature(targetSig) if targetPredicate != nil { if !b.pseudoReturnTypeMatchesPredicate(pt.ReturnType, targetPredicate) { - if reporter != nil { - reporter(pt.Signature) + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(pt.Signature) } return false } - } else if !b.pseudoTypeEquivalentToType(pt.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, reporter) { + } else if !b.pseudoTypeEquivalentToType(pt.ReturnType, b.ch.getReturnTypeOfSignature(targetSig), false, reportErrors) { // error reported within the return type return false } return true case pseudochecker.PseudoTypeKindNoResult: - if reporter != nil { - if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { - for _, n := range errorNodes { - reporter(n) - } - } else { - reporter(t.AsPseudoTypeNoResult().Declaration) - } - } - return false - case pseudochecker.PseudoTypeKindInferred: - if reporter != nil { - if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { - for _, n := range errorNodes { - reporter(n) - } - } else { - reporter(t.AsPseudoTypeInferred().Expression) - } + if reportErrors { + b.ctx.tracker.ReportInferenceFallback(t.AsPseudoTypeNoResult().Declaration) } return false default: @@ -556,16 +550,6 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } } -func isStructuralPseudoType(t *pseudochecker.PseudoType) bool { - switch t.Kind { - case pseudochecker.PseudoTypeKindObjectLiteral, pseudochecker.PseudoTypeKindTuple, pseudochecker.PseudoTypeKindSingleCallSignature: - return true - case pseudochecker.PseudoTypeKindMaybeConstLocation: - return isStructuralPseudoType(t.AsPseudoTypeMaybeConstLocation().ConstType) || isStructuralPseudoType(t.AsPseudoTypeMaybeConstLocation().RegularType) - } - return false -} - // pseudoReturnTypeMatchesPredicate checks if a pseudo return type (which should be a Direct type // wrapping a TypePredicateNode) matches the given type predicate from the checker. func (b *NodeBuilderImpl) pseudoReturnTypeMatchesPredicate(rt *pseudochecker.PseudoType, predicate *TypePredicate) bool { diff --git a/internal/pseudochecker/lookup.go b/internal/pseudochecker/lookup.go index e1d3b7618e6..43ce712513f 100644 --- a/internal/pseudochecker/lookup.go +++ b/internal/pseudochecker/lookup.go @@ -85,11 +85,10 @@ func (ch *PseudoChecker) typeFromPropertyAssignment(node *ast.Node) *PseudoType init := node.Initializer() if init != nil { expr := ch.typeFromExpression(init) - if expr != nil && expr.Kind != PseudoTypeKindInferred { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { return expr } - // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes - return NewPseudoTypeNoResultFromInferred(node, expr) + // fallback to NoResult if PseudoTypeKindInferred without error nodes } } return NewPseudoTypeNoResult(node) @@ -119,15 +118,14 @@ func (ch *PseudoChecker) typeFromProperty(node *ast.Node) *PseudoType { return NewPseudoTypeNoResult(node) } expr := ch.typeFromExpression(init) - if expr != nil && expr.Kind != PseudoTypeKindInferred { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { if expr.Kind != PseudoTypeKindDirect && node.AsPropertyDeclaration().PostfixToken != nil && node.AsPropertyDeclaration().PostfixToken.Kind == ast.KindQuestionToken { // type comes from the initializer expression on a property with a `?` - add `| undefined` to the type return addUndefinedIfDefinitelyRequired(expr) } return expr } - // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes - return NewPseudoTypeNoResultFromInferred(node, expr) + // fallback to NoResult if PseudoTypeKindInferred without error nodes } } return NewPseudoTypeNoResult(node) @@ -146,11 +144,10 @@ func (ch *PseudoChecker) typeFromVariable(declaration *ast.VariableDeclaration) return NewPseudoTypeNoResult(declaration.AsNode()) } expr := ch.typeFromExpression(init) - if expr != nil && expr.Kind != PseudoTypeKindInferred { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { return expr } - // fallback to NoResult if PseudoTypeKindInferred, preserving any error nodes - return NewPseudoTypeNoResultFromInferred(declaration.AsNode(), expr) + // fallback to NoResult if PseudoTypeKindInferred without error nodes } } return NewPseudoTypeNoResult(declaration.AsNode()) diff --git a/internal/pseudochecker/type.go b/internal/pseudochecker/type.go index ab8f6d40f0f..d3111272000 100644 --- a/internal/pseudochecker/type.go +++ b/internal/pseudochecker/type.go @@ -134,15 +134,6 @@ func NewPseudoTypeNoResult(decl *ast.Node) *PseudoType { return newPseudoType(PseudoTypeKindNoResult, &PseudoTypeNoResult{Declaration: decl}) } -// NewPseudoTypeNoResultFromInferred collapses a PseudoTypeInferred into a PseudoTypeNoResult -// for the given declaration, preserving any ErrorNodes from the inferred type. -func NewPseudoTypeNoResultFromInferred(decl *ast.Node, inferred *PseudoType) *PseudoType { - if inferred != nil && len(inferred.ErrorNodes()) > 0 { - return newPseudoTypeWithErrors(PseudoTypeKindNoResult, &PseudoTypeNoResult{Declaration: decl}, inferred.ErrorNodes()) - } - return NewPseudoTypeNoResult(decl) -} - func (t *PseudoType) AsPseudoTypeNoResult() *PseudoTypeNoResult { return t.data.(*PseudoTypeNoResult) } // PseudoTypeMaybeConstLocation encodes the const/regular types of a location so the builder diff --git a/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types b/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types index 9ec3885db2e..4d702402d00 100644 --- a/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types +++ b/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types @@ -46,8 +46,8 @@ export enum PubSubRecordIsStoredInRedisAsA { } const buildNameFieldConstructor = (soFar: SO_FAR) => ( ->buildNameFieldConstructor : (soFar: SO_FAR) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } ->(soFar: SO_FAR) => ( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } +>buildNameFieldConstructor : (soFar: SO_FAR) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } +>(soFar: SO_FAR) => ( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR >( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } @@ -103,8 +103,8 @@ export enum PubSubRecordIsStoredInRedisAsA { } const buildStoredAsConstructor = (soFar: SO_FAR) => ( ->buildStoredAsConstructor : (soFar: SO_FAR) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } ->(soFar: SO_FAR) => ( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : (soFar: SO_FAR) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } +>buildStoredAsConstructor : (soFar: SO_FAR) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } +>(soFar: SO_FAR) => ( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : (soFar: SO_FAR) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } >soFar : SO_FAR >( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } @@ -183,8 +183,8 @@ export enum PubSubRecordIsStoredInRedisAsA { } : {} const buildIdentifierFieldConstructor = (soFar: SO_FAR) => ( ->buildIdentifierFieldConstructor : (soFar: SO_FAR) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } ->(soFar: SO_FAR) => ( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } +>buildIdentifierFieldConstructor : (soFar: SO_FAR) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } +>(soFar: SO_FAR) => ( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR >( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } @@ -242,8 +242,8 @@ export enum PubSubRecordIsStoredInRedisAsA { } const buildRecordFieldConstructor = (soFar: SO_FAR) => ( ->buildRecordFieldConstructor : (soFar: SO_FAR) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } ->(soFar: SO_FAR) => ( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } +>buildRecordFieldConstructor : (soFar: SO_FAR) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } +>(soFar: SO_FAR) => ( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR >( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } @@ -376,8 +376,8 @@ export enum PubSubRecordIsStoredInRedisAsA { } : {} const buildType = (soFar: SO_FAR) => ( ->buildType : (soFar: SO_FAR) => {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } ->(soFar: SO_FAR) => ( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : (soFar: SO_FAR) => {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } +>buildType : (soFar: SO_FAR) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } +>(soFar: SO_FAR) => ( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : (soFar: SO_FAR) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } >soFar : SO_FAR >( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } @@ -452,22 +452,22 @@ export enum PubSubRecordIsStoredInRedisAsA { buildNameFieldConstructor(soFar), >buildNameFieldConstructor(soFar) : { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } ->buildNameFieldConstructor : (soFar: SO_FAR_1) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } +>buildNameFieldConstructor : (soFar: SO_FAR_1) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR buildIdentifierFieldConstructor(soFar), >buildIdentifierFieldConstructor(soFar) : { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } ->buildIdentifierFieldConstructor : (soFar: SO_FAR_1) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } +>buildIdentifierFieldConstructor : (soFar: SO_FAR_1) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR buildRecordFieldConstructor(soFar), >buildRecordFieldConstructor(soFar) : { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } ->buildRecordFieldConstructor : (soFar: SO_FAR_1) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } +>buildRecordFieldConstructor : (soFar: SO_FAR_1) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } >soFar : SO_FAR buildStoredAsConstructor(soFar), >buildStoredAsConstructor(soFar) : { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } ->buildStoredAsConstructor : (soFar: SO_FAR_1) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } +>buildStoredAsConstructor : (soFar: SO_FAR_1) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } >soFar : SO_FAR buildMaxMsToWaitBeforePublishingFieldConstructor(soFar), @@ -477,7 +477,7 @@ export enum PubSubRecordIsStoredInRedisAsA { buildType(soFar) >buildType(soFar) : { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } ->buildType : (soFar: SO_FAR_1) => {} | { type: SO_FAR_1; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } +>buildType : (soFar: SO_FAR_1) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR_1; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } >soFar : SO_FAR ) as BuildPubSubRecordType; diff --git a/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types.diff b/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types.diff deleted file mode 100644 index f2e505b4c53..00000000000 --- a/testdata/baselines/reference/submodule/compiler/conditionalTypeDoesntSpinForever.types.diff +++ /dev/null @@ -1,93 +0,0 @@ ---- old.conditionalTypeDoesntSpinForever.types -+++ new.conditionalTypeDoesntSpinForever.types -@@= skipped -45, +45 lines =@@ - } - - const buildNameFieldConstructor = (soFar: SO_FAR) => ( -->buildNameFieldConstructor : (soFar: SO_FAR) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } -->(soFar: SO_FAR) => ( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildNameFieldConstructor : (soFar: SO_FAR) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } -+>(soFar: SO_FAR) => ( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - >( "name" in soFar ? {} : { name: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {name: instance as TYPE}) as SO_FAR & {name: TYPE}) as BuildPubSubRecordType } ) : {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } - -@@= skipped -57, +57 lines =@@ - } - - const buildStoredAsConstructor = (soFar: SO_FAR) => ( -->buildStoredAsConstructor : (soFar: SO_FAR) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } -->(soFar: SO_FAR) => ( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : (soFar: SO_FAR) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } -+>buildStoredAsConstructor : (soFar: SO_FAR) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } -+>(soFar: SO_FAR) => ( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : (soFar: SO_FAR) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } - >soFar : SO_FAR - >( "storedAs" in soFar ? {} : { storedAsJsonEncodedRedisString: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.jsonEncodedRedisString})) as BuildPubSubRecordType, storedAsRedisHash: () => buildPubSubRecordType(Object.assign({}, soFar, {storedAs: PubSubRecordIsStoredInRedisAsA.redisHash})) as BuildPubSubRecordType, } ) : {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } - -@@= skipped -80, +80 lines =@@ - } : {} - - const buildIdentifierFieldConstructor = (soFar: SO_FAR) => ( -->buildIdentifierFieldConstructor : (soFar: SO_FAR) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } -->(soFar: SO_FAR) => ( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildIdentifierFieldConstructor : (soFar: SO_FAR) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } -+>(soFar: SO_FAR) => ( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - >( "identifier" in soFar || (!("record" in soFar)) ? {} : { identifier: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {identifier: instance as TYPE}) as SO_FAR & {identifier: TYPE}) as BuildPubSubRecordType } ) : {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } - -@@= skipped -59, +59 lines =@@ - } - - const buildRecordFieldConstructor = (soFar: SO_FAR) => ( -->buildRecordFieldConstructor : (soFar: SO_FAR) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } -->(soFar: SO_FAR) => ( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildRecordFieldConstructor : (soFar: SO_FAR) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } -+>(soFar: SO_FAR) => ( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : (soFar: SO_FAR) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - >( "record" in soFar ? {} : { record: (instance: TYPE = undefined) => buildPubSubRecordType(Object.assign({}, soFar, {record: instance as TYPE}) as SO_FAR & {record: TYPE}) as BuildPubSubRecordType } ) : {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } - -@@= skipped -134, +134 lines =@@ - } : {} - - const buildType = (soFar: SO_FAR) => ( -->buildType : (soFar: SO_FAR) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } -->(soFar: SO_FAR) => ( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : (soFar: SO_FAR) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } -+>buildType : (soFar: SO_FAR) => {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } -+>(soFar: SO_FAR) => ( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : (soFar: SO_FAR) => {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } - >soFar : SO_FAR - >( "identifier" in soFar && "object" in soFar && "maxMsToWaitBeforePublishing" in soFar && "PubSubRecordIsStoredInRedisAsA" in soFar ? {} : { type: soFar, fields: () => new Set(Object.keys(soFar) as (keyof SO_FAR)[]), hasField: (fieldName: string | number | symbol) => fieldName in soFar } ) : {} | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } - -@@= skipped -76, +76 lines =@@ - - buildNameFieldConstructor(soFar), - >buildNameFieldConstructor(soFar) : { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } -->buildNameFieldConstructor : (soFar: SO_FAR_1) => { name?: undefined; } | { name: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildNameFieldConstructor : (soFar: SO_FAR_1) => {} | { name: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - - buildIdentifierFieldConstructor(soFar), - >buildIdentifierFieldConstructor(soFar) : { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } -->buildIdentifierFieldConstructor : (soFar: SO_FAR_1) => { identifier?: undefined; } | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildIdentifierFieldConstructor : (soFar: SO_FAR_1) => {} | { identifier: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - - buildRecordFieldConstructor(soFar), - >buildRecordFieldConstructor(soFar) : { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } -->buildRecordFieldConstructor : (soFar: SO_FAR_1) => { record?: undefined; } | { record: (instance?: TYPE) => BuildPubSubRecordType; } -+>buildRecordFieldConstructor : (soFar: SO_FAR_1) => {} | { record: (instance?: TYPE) => BuildPubSubRecordType; } - >soFar : SO_FAR - - buildStoredAsConstructor(soFar), - >buildStoredAsConstructor(soFar) : { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } -->buildStoredAsConstructor : (soFar: SO_FAR_1) => { storedAsJsonEncodedRedisString?: undefined; storedAsRedisHash?: undefined; } | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } -+>buildStoredAsConstructor : (soFar: SO_FAR_1) => {} | { storedAsJsonEncodedRedisString: () => BuildPubSubRecordType; storedAsRedisHash: () => BuildPubSubRecordType; } - >soFar : SO_FAR - - buildMaxMsToWaitBeforePublishingFieldConstructor(soFar), -@@= skipped -25, +25 lines =@@ - - buildType(soFar) - >buildType(soFar) : { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } -->buildType : (soFar: SO_FAR_1) => { type?: undefined; fields?: undefined; hasField?: undefined; } | { type: SO_FAR_1; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } -+>buildType : (soFar: SO_FAR_1) => {} | { type: SO_FAR_1; fields: () => Set; hasField: (fieldName: string | number | symbol) => boolean; } - >soFar : SO_FAR - - ) as BuildPubSubRecordType; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt index b07df12ef54..1c78fa1a4f5 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt @@ -1,7 +1,6 @@ a.ts(1,16): error TS9037: Default exports can't be inferred with --isolatedDeclarations. b.ts(1,23): error TS9013: Expression type can't be inferred with --isolatedDeclarations. c.ts(1,16): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. -c.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. d.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. @@ -20,15 +19,11 @@ e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDecla !!! related TS9036 b.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. !!! related TS9035 b.ts:1:23: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. -==== c.ts (2 errors) ==== +==== c.ts (1 errors) ==== export default [{ foo: 1 + 1 }]; ~~~~~~~~~~~~~~~~ !!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. !!! related TS9036 c.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -!!! related TS9036 c.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 c.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ==== d.ts (1 errors) ==== export default [{ foo: 1 + 1 }] as const; diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt.diff deleted file mode 100644 index 251537b48dd..00000000000 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsDefault.errors.txt.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- old.isolatedDeclarationErrorsDefault.errors.txt -+++ new.isolatedDeclarationErrorsDefault.errors.txt -@@= skipped -0, +0 lines =@@ - a.ts(1,16): error TS9037: Default exports can't be inferred with --isolatedDeclarations. - b.ts(1,23): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - c.ts(1,16): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. -+c.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - d.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - -@@= skipped -18, +19 lines =@@ - !!! related TS9036 b.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. - !!! related TS9035 b.ts:1:23: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - --==== c.ts (1 errors) ==== -+==== c.ts (2 errors) ==== - export default [{ foo: 1 + 1 }]; - ~~~~~~~~~~~~~~~~ - !!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. - !!! related TS9036 c.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+!!! related TS9036 c.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -+!!! related TS9035 c.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - - ==== d.ts (1 errors) ==== - export default [{ foo: 1 + 1 }] as const; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt index 8fa23907bd2..e062db06c34 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt @@ -1,9 +1,11 @@ isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. @@ -19,7 +21,7 @@ isolatedDeclarationErrorsObjects.ts(77,5): error TS9016: Objects that contain sh isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== +==== isolatedDeclarationErrorsObjects.ts (21 errors) ==== export let o = { a: 1, b: "" @@ -42,13 +44,20 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. }, c: { + ~ d: 1, + ~~~~~~~~~~~~~ e: V, + ~~~~~~~~~~~~~ ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } export let oWithMethods = { @@ -72,19 +81,28 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp } export let oWithMethodsNested = { foo: { + ~ method() { }, + ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method a: 1, + ~~~~~~~~~~~~~ okMethod(): void { }, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bad() { } + ~~~~~~~~~~~~~~~~~ ~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method } + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff new file mode 100644 index 00000000000..264fa86780a --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff @@ -0,0 +1,73 @@ +--- old.isolatedDeclarationErrorsObjects.errors.txt ++++ new.isolatedDeclarationErrorsObjects.errors.txt +@@= skipped -0, +0 lines =@@ + isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. ++isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. ++isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +@@= skipped -18, +20 lines =@@ + isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. + + +-==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== ++==== isolatedDeclarationErrorsObjects.ts (21 errors) ==== + export let o = { + a: 1, + b: "" +@@= skipped -23, +23 lines =@@ + !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + }, + c: { ++ ~ + d: 1, ++ ~~~~~~~~~~~~~ + e: V, ++ ~~~~~~~~~~~~~ + ~ + !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. + !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + } ++ ~~~~~ ++!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. ++!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. ++!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + } + + export let oWithMethods = { +@@= skipped -30, +37 lines =@@ + } + export let oWithMethodsNested = { + foo: { ++ ~ + method() { }, ++ ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ + !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. + !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method + a: 1, ++ ~~~~~~~~~~~~~ + okMethod(): void { }, ++ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + bad() { } ++ ~~~~~~~~~~~~~~~~~ + ~~~ + !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. + !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. + !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method + } ++ ~~~~~ ++!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. ++!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. ++!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + } + + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js index 6566c591417..4d32902a6be 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js @@ -31,16 +31,12 @@ declare const j: { x: number; y: number; obj: { - items: ({ + "items": ({ x: number; - y?: undefined; - err?: undefined; } | { x: number; y: number; - err?: undefined; } | { - y?: undefined; x: number; err: boolean; })[]; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js.diff index e9775fb05e1..42861d3c670 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js.diff @@ -8,7 +8,20 @@ declare const j: { x: number; y: number; -@@= skipped -20, +19 lines =@@ + obj: { +- items: ({ ++ "items": ({ + x: number; +- y?: undefined; +- err?: undefined; + } | { + x: number; + y: number; +- err?: undefined; + } | { +- y?: undefined; + x: number; + err: boolean; })[]; }; }; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types index a5060d152d4..95528b53263 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types @@ -2,17 +2,17 @@ === index.js === const j = require("./obj.json"); ->j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ->require("./obj.json") : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +>j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } +>require("./obj.json") : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } >require : any >"./obj.json" : "./obj.json" module.exports = j; ->module.exports = j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ->module.exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ->module : { "export=": { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; }; } ->exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ->j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +>module.exports = j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } +>module.exports : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } +>module : { "export=": { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; }; } +>exports : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } +>j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } === obj.json === { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types.diff index 6dabadc96fc..6d4fbaa2def 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).types.diff @@ -1,10 +1,27 @@ --- old.jsDeclarationsJson(target=es2015).types +++ new.jsDeclarationsJson(target=es2015).types -@@= skipped -9, +9 lines =@@ +@@= skipped -1, +1 lines =@@ + + === index.js === + const j = require("./obj.json"); +->j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +->require("./obj.json") : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ++>j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } ++>require("./obj.json") : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } + >require : any + >"./obj.json" : "./obj.json" + module.exports = j; - >module.exports = j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } - >module.exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +->module.exports = j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +->module.exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ->module : { exports: { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; }; } -+>module : { "export=": { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; }; } - >exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } - >j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +->exports : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } +->j : { x: number; y: number; obj: { items: ({ x: number; y?: undefined; err?: undefined; } | { x: number; y: number; err?: undefined; } | { y?: undefined; x: number; err: boolean; })[]; }; } ++>module.exports = j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } ++>module.exports : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } ++>module : { "export=": { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; }; } ++>exports : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } ++>j : { x: number; y: number; obj: { "items": ({ x: number; } | { x: number; y: number; } | { x: number; err: boolean; })[]; }; } + + === obj.json === + { \ No newline at end of file From 543a90d21f498a559d68e7aadbb44e1e86268176 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 26 Mar 2026 19:32:21 -0700 Subject: [PATCH 3/5] more --- internal/checker/pseudotypenodebuilder.go | 13 +++- ...solatedDeclarationErrorsObjects.errors.txt | 20 +---- ...edDeclarationErrorsObjects.errors.txt.diff | 73 ------------------- 3 files changed, 13 insertions(+), 93 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff diff --git a/internal/checker/pseudotypenodebuilder.go b/internal/checker/pseudotypenodebuilder.go index e0fc358bb84..5a105ee6188 100644 --- a/internal/checker/pseudotypenodebuilder.go +++ b/internal/checker/pseudotypenodebuilder.go @@ -410,7 +410,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType case pseudochecker.PseudoObjectElementKindPropertyAssignment: d := e.AsPseudoPropertyAssignment() if !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, false) { - if reportErrors { + if reportErrors && !isStructuralPseudoType(d.Type) { b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) } return false @@ -550,6 +550,17 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType } } +func isStructuralPseudoType(t *pseudochecker.PseudoType) bool { + switch t.Kind { + case pseudochecker.PseudoTypeKindObjectLiteral, pseudochecker.PseudoTypeKindTuple, pseudochecker.PseudoTypeKindSingleCallSignature: + return true + case pseudochecker.PseudoTypeKindMaybeConstLocation: + d := t.AsPseudoTypeMaybeConstLocation() + return isStructuralPseudoType(d.ConstType) || isStructuralPseudoType(d.RegularType) + } + return false +} + // pseudoReturnTypeMatchesPredicate checks if a pseudo return type (which should be a Direct type // wrapping a TypePredicateNode) matches the given type predicate from the checker. func (b *NodeBuilderImpl) pseudoReturnTypeMatchesPredicate(rt *pseudochecker.PseudoType, predicate *TypePredicate) bool { diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt index e062db06c34..8fa23907bd2 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt @@ -1,11 +1,9 @@ isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. @@ -21,7 +19,7 @@ isolatedDeclarationErrorsObjects.ts(77,5): error TS9016: Objects that contain sh isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. -==== isolatedDeclarationErrorsObjects.ts (21 errors) ==== +==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== export let o = { a: 1, b: "" @@ -44,20 +42,13 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. }, c: { - ~ d: 1, - ~~~~~~~~~~~~~ e: V, - ~~~~~~~~~~~~~ ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } export let oWithMethods = { @@ -81,28 +72,19 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp } export let oWithMethodsNested = { foo: { - ~ method() { }, - ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method a: 1, - ~~~~~~~~~~~~~ okMethod(): void { }, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bad() { } - ~~~~~~~~~~~~~~~~~ ~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method } - ~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff deleted file mode 100644 index 264fa86780a..00000000000 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsObjects.errors.txt.diff +++ /dev/null @@ -1,73 +0,0 @@ ---- old.isolatedDeclarationErrorsObjects.errors.txt -+++ new.isolatedDeclarationErrorsObjects.errors.txt -@@= skipped -0, +0 lines =@@ - isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(14,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+isolatedDeclarationErrorsObjects.ts(28,10): error TS9013: Expression type can't be inferred with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. -@@= skipped -18, +20 lines =@@ - isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. - - --==== isolatedDeclarationErrorsObjects.ts (19 errors) ==== -+==== isolatedDeclarationErrorsObjects.ts (21 errors) ==== - export let o = { - a: 1, - b: "" -@@= skipped -23, +23 lines =@@ - !!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - }, - c: { -+ ~ - d: 1, -+ ~~~~~~~~~~~~~ - e: V, -+ ~~~~~~~~~~~~~ - ~ - !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. - !!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -+!!! related TS9035 isolatedDeclarationErrorsObjects.ts:14:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } - - export let oWithMethods = { -@@= skipped -30, +37 lines =@@ - } - export let oWithMethodsNested = { - foo: { -+ ~ - method() { }, -+ ~~~~~~~~~~~~~~~~~~~~~ - ~~~~~~ - !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. - !!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method - a: 1, -+ ~~~~~~~~~~~~~ - okMethod(): void { }, -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - bad() { } -+ ~~~~~~~~~~~~~~~~~ - ~~~ - !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. - !!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. - !!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method - } -+ ~~~~~ -+!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. -+!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. -+!!! related TS9035 isolatedDeclarationErrorsObjects.ts:28:10: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. - } - - \ No newline at end of file From e67b189ca097323a7bce0c45fb46ffa065297c81 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:19:31 -0700 Subject: [PATCH 4/5] Move ErrorNodes onto inferred --- internal/checker/pseudotypenodebuilder.go | 6 +++--- internal/pseudochecker/lookup.go | 6 +++--- internal/pseudochecker/type.go | 20 +++++--------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/internal/checker/pseudotypenodebuilder.go b/internal/checker/pseudotypenodebuilder.go index 5a105ee6188..e00b4698786 100644 --- a/internal/checker/pseudotypenodebuilder.go +++ b/internal/checker/pseudotypenodebuilder.go @@ -15,7 +15,7 @@ import ( func (b *NodeBuilderImpl) pseudoTypeToNodeWithCheckerFallback(t *pseudochecker.PseudoType, checkerType *Type) *ast.Node { if t.Kind == pseudochecker.PseudoTypeKindInferred { if !b.ctx.suppressReportInferenceFallback { - if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + if errorNodes := t.AsPseudoTypeInferred().ErrorNodes; len(errorNodes) > 0 { for _, n := range errorNodes { b.ctx.tracker.ReportInferenceFallback(n) } @@ -41,7 +41,7 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod case pseudochecker.PseudoTypeKindInferred: inferred := t.AsPseudoTypeInferred() node := inferred.Expression - if errorNodes := t.ErrorNodes(); len(errorNodes) > 0 { + if errorNodes := inferred.ErrorNodes; len(errorNodes) > 0 { for _, n := range errorNodes { b.ctx.tracker.ReportInferenceFallback(n) } @@ -353,7 +353,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType // PseudoTypeInferred with error nodes is always considered equivalent — // the error nodes identify specific problematic children, and pseudoTypeToNodeWithCheckerFallback // will report errors on them and fall back to the checker's real type. - if len(t.ErrorNodes()) > 0 { + if len(t.AsPseudoTypeInferred().ErrorNodes) > 0 { return true } if reportErrors { diff --git a/internal/pseudochecker/lookup.go b/internal/pseudochecker/lookup.go index 43ce712513f..ff5b768023d 100644 --- a/internal/pseudochecker/lookup.go +++ b/internal/pseudochecker/lookup.go @@ -85,7 +85,7 @@ func (ch *PseudoChecker) typeFromPropertyAssignment(node *ast.Node) *PseudoType init := node.Initializer() if init != nil { expr := ch.typeFromExpression(init) - if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.AsPseudoTypeInferred().ErrorNodes) > 0) { return expr } // fallback to NoResult if PseudoTypeKindInferred without error nodes @@ -118,7 +118,7 @@ func (ch *PseudoChecker) typeFromProperty(node *ast.Node) *PseudoType { return NewPseudoTypeNoResult(node) } expr := ch.typeFromExpression(init) - if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.AsPseudoTypeInferred().ErrorNodes) > 0) { if expr.Kind != PseudoTypeKindDirect && node.AsPropertyDeclaration().PostfixToken != nil && node.AsPropertyDeclaration().PostfixToken.Kind == ast.KindQuestionToken { // type comes from the initializer expression on a property with a `?` - add `| undefined` to the type return addUndefinedIfDefinitelyRequired(expr) @@ -144,7 +144,7 @@ func (ch *PseudoChecker) typeFromVariable(declaration *ast.VariableDeclaration) return NewPseudoTypeNoResult(declaration.AsNode()) } expr := ch.typeFromExpression(init) - if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.ErrorNodes()) > 0) { + if expr != nil && (expr.Kind != PseudoTypeKindInferred || len(expr.AsPseudoTypeInferred().ErrorNodes) > 0) { return expr } // fallback to NoResult if PseudoTypeKindInferred without error nodes diff --git a/internal/pseudochecker/type.go b/internal/pseudochecker/type.go index d3111272000..d9a8d1816eb 100644 --- a/internal/pseudochecker/type.go +++ b/internal/pseudochecker/type.go @@ -42,15 +42,10 @@ const ( ) type PseudoType struct { - Kind PseudoTypeKind - errorNodes []*ast.Node - data pseudoTypeData + Kind PseudoTypeKind + data pseudoTypeData } -// ErrorNodes returns the specific child nodes that caused an inference failure, -// collected during pseudochecker construction. Nil/empty means no specific children. -func (t *PseudoType) ErrorNodes() []*ast.Node { return t.errorNodes } - func newPseudoType(kind PseudoTypeKind, data pseudoTypeData) *PseudoType { n := data.AsPseudoType() n.Kind = kind @@ -58,12 +53,6 @@ func newPseudoType(kind PseudoTypeKind, data pseudoTypeData) *PseudoType { return n } -func newPseudoTypeWithErrors(kind PseudoTypeKind, data pseudoTypeData, errorNodes []*ast.Node) *PseudoType { - n := newPseudoType(kind, data) - n.errorNodes = errorNodes - return n -} - type pseudoTypeData interface { AsPseudoType() *PseudoType } @@ -106,10 +95,11 @@ func (t *PseudoType) AsPseudoTypeDirect() *PseudoTypeDirect { return t.data.(*Ps // These represent cases where the expression was too complex for the pseudochecker. // Most of the time, these locations will produce an error under ID. // Specific error nodes (shorthand properties, spread assignments, etc.) are stored on the -// PseudoType.errorNodes field, collected during pseudochecker construction. +// ErrorNodes field, collected during pseudochecker construction. type PseudoTypeInferred struct { PseudoTypeBase Expression *ast.Node + ErrorNodes []*ast.Node } func NewPseudoTypeInferred(expr *ast.Node) *PseudoType { @@ -117,7 +107,7 @@ func NewPseudoTypeInferred(expr *ast.Node) *PseudoType { } func NewPseudoTypeInferredWithErrors(expr *ast.Node, errorNodes []*ast.Node) *PseudoType { - return newPseudoTypeWithErrors(PseudoTypeKindInferred, &PseudoTypeInferred{Expression: expr}, errorNodes) + return newPseudoType(PseudoTypeKindInferred, &PseudoTypeInferred{Expression: expr, ErrorNodes: errorNodes}) } func (t *PseudoType) AsPseudoTypeInferred() *PseudoTypeInferred { return t.data.(*PseudoTypeInferred) } From ff5138d7140fbdcac7e3e685591748d60e1bbade Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:44:57 -0700 Subject: [PATCH 5/5] Don't do the nil check thing --- internal/pseudochecker/lookup.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/pseudochecker/lookup.go b/internal/pseudochecker/lookup.go index ff5b768023d..437e6b5408b 100644 --- a/internal/pseudochecker/lookup.go +++ b/internal/pseudochecker/lookup.go @@ -419,20 +419,19 @@ func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpr var errorNodes []*ast.Node for _, e := range node.Properties.Nodes { if e.Flags&ast.NodeFlagsThisNodeHasError != 0 { - // Return empty (non-nil) slice to signal failure without specific error nodes - return []*ast.Node{} + errorNodes = append(errorNodes, e) + continue } if e.Kind == ast.KindShorthandPropertyAssignment || e.Kind == ast.KindSpreadAssignment { errorNodes = append(errorNodes, e) continue } if e.Name().Flags&ast.NodeFlagsThisNodeHasError != 0 { - return []*ast.Node{} + errorNodes = append(errorNodes, e.Name()) + continue } if e.Name().Kind == ast.KindPrivateIdentifier { - if errorNodes == nil { - errorNodes = []*ast.Node{} // signal failure - } + errorNodes = append(errorNodes, e) continue } if e.Name().Kind == ast.KindComputedPropertyName {