From e190e9be977f2216f66f6b072ad0fda1571b8f28 Mon Sep 17 00:00:00 2001 From: Zyad Haddad <128618322+Trighap52@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:52:15 +0200 Subject: [PATCH 1/2] Preserve computed property names in isolated declaration emit Fixes #61892. --- tsc/internal/checker/nodebuilderimpl.go | 2 +- tsc/internal/checker/pseudotypenodebuilder.go | 8 + tsc/internal/pseudochecker/checker.go | 5 +- tsc/internal/pseudochecker/lookup.go | 12 +- .../transformers/declarations/transform.go | 26 ++- .../computedPropertiesNarrowed.errors.txt | 22 +- ...solatedDeclarationErrorsClasses.errors.txt | 27 +-- ...solatedDeclarationErrorsObjects.errors.txt | 14 +- .../isolatedDeclarationLazySymbols.errors.txt | 6 +- .../isolatedDeclarationsComputedProperties.js | 141 ++++++++++++ ...atedDeclarationsComputedProperties.symbols | 169 +++++++++++++++ ...olatedDeclarationsComputedProperties.types | 201 ++++++++++++++++++ ...rationsComputedPropertiesErrors.errors.txt | 38 ++++ ...tedDeclarationsComputedPropertiesErrors.js | 31 +++ ...clarationsComputedPropertiesErrors.symbols | 44 ++++ ...DeclarationsComputedPropertiesErrors.types | 56 +++++ ...tionBasicSyntax(declarationMap=false).d.ts | 10 +- ...ationBasicSyntax(declarationMap=true).d.ts | 12 +- .../declarationComputedPropertyNames.d.ts | 43 +--- ...declarationPreserveComputedProperties.d.ts | 93 ++++++++ .../declarationPreserveComputedProperties.js | 87 ++++++++ .../isolatedDeclarationsComputedProperties.ts | 52 +++++ ...tedDeclarationsComputedPropertiesErrors.ts | 19 ++ .../declarationPreserveComputedProperties.ts | 52 +++++ 24 files changed, 1048 insertions(+), 122 deletions(-) create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types create mode 100644 tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.d.ts create mode 100644 tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.js create mode 100644 tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts create mode 100644 tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts create mode 100644 tsc/testdata/tests/cases/transpile/declarationPreserveComputedProperties.ts diff --git a/tsc/internal/checker/nodebuilderimpl.go b/tsc/internal/checker/nodebuilderimpl.go index cd4643ac6f273..0f4b24962329c 100644 --- a/tsc/internal/checker/nodebuilderimpl.go +++ b/tsc/internal/checker/nodebuilderimpl.go @@ -127,7 +127,7 @@ func newNodeBuilderImpl(ch *Checker, e *printer.EmitContext, idToSymbol map[*ast if idToSymbol == nil { idToSymbol = make(map[*ast.IdentifierNode]*ast.Symbol) } - b := &NodeBuilderImpl{f: e.Factory.AsNodeFactory(), ch: ch, e: e, idToSymbol: idToSymbol, pc: pseudochecker.NewPseudoChecker(ch.strictNullChecks, ch.exactOptionalPropertyTypes)} + b := &NodeBuilderImpl{f: e.Factory.AsNodeFactory(), ch: ch, e: e, idToSymbol: idToSymbol, pc: pseudochecker.NewPseudoChecker(ch.strictNullChecks, ch.exactOptionalPropertyTypes, ch.compilerOptions.IsolatedDeclarations.IsTrue())} b.cloneBindingNameVisitor = ast.NewNodeVisitor(b.cloneBindingName, b.f, ast.NodeVisitorHooks{}) return b } diff --git a/tsc/internal/checker/pseudotypenodebuilder.go b/tsc/internal/checker/pseudotypenodebuilder.go index 40ca59da0ebec..1ebe3b1916624 100644 --- a/tsc/internal/checker/pseudotypenodebuilder.go +++ b/tsc/internal/checker/pseudotypenodebuilder.go @@ -2,6 +2,7 @@ package checker import ( "github.com/microsoft/TypeScript/tsc/internal/ast" + "github.com/microsoft/TypeScript/tsc/internal/core" "github.com/microsoft/TypeScript/tsc/internal/debug" "github.com/microsoft/TypeScript/tsc/internal/nodebuilder" "github.com/microsoft/TypeScript/tsc/internal/printer" @@ -420,6 +421,13 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType if type_ == nil { return false } + if b.ch.compilerOptions.IsolatedDeclarations.IsTrue() && core.Some(pt.Elements, func(e *pseudochecker.PseudoObjectElement) bool { + return ast.IsComputedPropertyName(e.Name) && ast.IsEntityNameExpression(e.Name.Expression()) + }) { + // Computed names can resolve to overlapping properties or index signatures. Preserve the + // syntactic members rather than comparing them with the checker's merged object shape. + return true + } targetProps := b.ch.getPropertiesOfType(undefinedStripped) // Count total declarations across all target prop symbols to handle getter/setter pairs, // which are two elements in pt.Elements but only one symbol in targetProps. diff --git a/tsc/internal/pseudochecker/checker.go b/tsc/internal/pseudochecker/checker.go index b9baa07f40ba8..4f074d8eb1820 100644 --- a/tsc/internal/pseudochecker/checker.go +++ b/tsc/internal/pseudochecker/checker.go @@ -14,8 +14,9 @@ package pseudochecker type PseudoChecker struct { strictNullChecks bool exactOptionalPropertyTypes bool + preserveComputedNames bool } -func NewPseudoChecker(strictNullChecks bool, exactOptionalPropertyTypes bool) *PseudoChecker { - return &PseudoChecker{strictNullChecks: strictNullChecks, exactOptionalPropertyTypes: exactOptionalPropertyTypes} +func NewPseudoChecker(strictNullChecks bool, exactOptionalPropertyTypes bool, preserveComputedNames bool) *PseudoChecker { + return &PseudoChecker{strictNullChecks: strictNullChecks, exactOptionalPropertyTypes: exactOptionalPropertyTypes, preserveComputedNames: preserveComputedNames} } diff --git a/tsc/internal/pseudochecker/lookup.go b/tsc/internal/pseudochecker/lookup.go index 3fc7243df41f5..b53c382ca9d67 100644 --- a/tsc/internal/pseudochecker/lookup.go +++ b/tsc/internal/pseudochecker/lookup.go @@ -361,6 +361,14 @@ func (ch *PseudoChecker) typeFromObjectLiteral(node *ast.ObjectLiteralExpression // roughly analogous to typeFromObjectLiteralAccessor in strada func (ch *PseudoChecker) getAccessorMember(accessor *ast.Node, name *ast.Node) *PseudoObjectElement { + if ch.preserveComputedNames && ast.IsComputedPropertyName(name) && ast.IsEntityNameExpression(name.Expression()) { + // Computed accessors cannot be paired using their bound symbols alone. Preserve each + // accessor so the declaration checker can resolve the computed names and pair them. + if ast.IsGetAccessorDeclaration(accessor) { + return NewPseudoGetAccessor(accessor, name, false, ch.typeFromAccessor(accessor)) + } + return NewPseudoSetAccessor(accessor, name, false, ch.cloneParameters(accessor.ParameterList())[0]) + } allAccessors := ast.GetAllAccessorDeclarationsForDeclaration(accessor, accessor.Symbol().Declarations()) // TODO: node preservation for late-bound accessor pairs? // TODO: handle pseudo-annotations from get accessor return positions? @@ -402,7 +410,7 @@ func (ch *PseudoChecker) getAccessorMember(accessor *ast.Node, name *ast.Node) * // 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. +// computed names that cannot be preserved) that prevent typing. func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpression) []*ast.Node { if node.Properties == nil || len(node.Properties.Nodes) == 0 { return nil // empty object, ok @@ -427,7 +435,7 @@ func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpr } if e.Name().Kind == ast.KindComputedPropertyName { expression := e.Name().Expression() - if !ast.IsPrimitiveLiteralValue(expression, false) { + if !ast.IsPrimitiveLiteralValue(expression, false) && !(ch.preserveComputedNames && ast.IsEntityNameExpression(expression)) { errorNodes = append(errorNodes, e.Name()) } } diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index f0187f2f2590c..06d9592702334 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -574,13 +574,12 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast. } if ast.HasDynamicName(input) { if tx.state.isolatedDeclarations { - // Classes and object literals usually elide properties with computed names that are not of a literal type - // In isolated declarations TSC needs to error on these as we don't know the type in a DTE. - if !tx.resolver.IsDefinitelyReferenceToGlobalSymbolObject(input.Name().Expression()) { + // Entity name expressions can be preserved without knowing the type of the computed name. + if !ast.IsEntityNameExpression(input.Name().Expression()) && !tx.resolver.IsDefinitelyReferenceToGlobalSymbolObject(input.Name().Expression()) { if ast.IsClassDeclaration(input.Parent) || ast.IsObjectLiteralExpression(input.Parent) { tx.state.addDiagnostic(createDiagnosticForNode(input, diagnostics.Computed_property_names_on_class_or_object_literals_cannot_be_inferred_with_isolatedDeclarations)) return nil - } else if (ast.IsInterfaceDeclaration(input.Parent) || ast.IsTypeLiteralNode(input.Parent)) && !ast.IsEntityNameExpression(input.Name().Expression()) { + } else if ast.IsInterfaceDeclaration(input.Parent) || ast.IsTypeLiteralNode(input.Parent) { // Type declarations just need to double-check that the input computed name is an entity name expression tx.state.addDiagnostic(createDiagnosticForNode(input, diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations)) return nil @@ -1965,13 +1964,18 @@ func (tx *DeclarationTransformer) buildClassMembers(classNode *ast.Node, extraMe privateIdentifier = tx.Factory().NewPropertyDeclaration(nil, tx.Factory().NewPrivateIdentifier("#private"), nil, nil, nil) } - lateIndexes := tx.resolver.CreateLateBoundIndexSignatures( - classNode, - tx.enclosingDeclaration, - declarationEmitNodeBuilderFlags, - declarationEmitInternalNodeBuilderFlags, - tx.tracker, - ) + var lateIndexes []*ast.Node + if !tx.state.isolatedDeclarations { + // Isolated declaration emit preserves the computed members themselves, so their + // inferred index signatures must not add another copy of those members. + lateIndexes = tx.resolver.CreateLateBoundIndexSignatures( + classNode, + tx.enclosingDeclaration, + declarationEmitNodeBuilderFlags, + declarationEmitInternalNodeBuilderFlags, + tx.tracker, + ) + } memberNodes := make([]*ast.Node, 0, len(classNode.ClassLikeData().Members.Nodes)) if privateIdentifier != nil { diff --git a/tsc/testdata/baselines/reference/compiler/computedPropertiesNarrowed.errors.txt b/tsc/testdata/baselines/reference/compiler/computedPropertiesNarrowed.errors.txt index 3d6bf4c8cc890..17db9749fa837 100644 --- a/tsc/testdata/baselines/reference/compiler/computedPropertiesNarrowed.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/computedPropertiesNarrowed.errors.txt @@ -1,33 +1,22 @@ -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 (10 errors) ==== +==== computedPropertiesNarrowed.ts (5 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. -!!! related TS9027 computedPropertiesNarrowed.ts:4:12: Add a type annotation to the variable o. } 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. -!!! related TS9027 computedPropertiesNarrowed.ts:10:12: Add a type annotation to the variable o2. } // literals are ok @@ -45,9 +34,6 @@ computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on cl !!! 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. -!!! related TS9027 computedPropertiesNarrowed.ts:21:12: Add a type annotation to the variable o4. } export let o5 ={ @@ -60,9 +46,6 @@ computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on cl 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. -!!! related TS9027 computedPropertiesNarrowed.ts:30:12: Add a type annotation to the variable o6. } @@ -77,9 +60,6 @@ computedPropertiesNarrowed.ts(47,5): error TS9038: Computed property names on cl 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. -!!! related TS9027 computedPropertiesNarrowed.ts:41:14: Add a type annotation to the variable o8. } function ns() { return { v: 0 } as const } diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsClasses.errors.txt b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsClasses.errors.txt index 7e9b2904f7a2e..021e319bed5fb 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsClasses.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsClasses.errors.txt @@ -7,26 +7,20 @@ isolatedDeclarationErrorsClasses.ts(11,9): error TS9009: At least one accessor m isolatedDeclarationErrorsClasses.ts(12,9): error TS7032: Property 'setOnly' implicitly has type 'any', because its set accessor lacks a parameter type annotation. isolatedDeclarationErrorsClasses.ts(12,17): error TS7006: Parameter 'value' implicitly has an 'any' type. isolatedDeclarationErrorsClasses.ts(12,17): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsClasses.ts(36,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(36,6): error TS2304: Cannot find name 'missing'. -isolatedDeclarationErrorsClasses.ts(38,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsClasses.ts(40,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(42,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsClasses.ts(42,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -isolatedDeclarationErrorsClasses.ts(44,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(44,35): error TS7006: Parameter 'v' implicitly has an 'any' type. isolatedDeclarationErrorsClasses.ts(44,35): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsClasses.ts(46,9): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(48,9): error TS7032: Property '[noParamAnnotationStringName]' implicitly has type 'any', because its set accessor lacks a parameter type annotation. -isolatedDeclarationErrorsClasses.ts(48,9): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(48,39): error TS7006: Parameter 'value' implicitly has an 'any' type. +isolatedDeclarationErrorsClasses.ts(48,39): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(50,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. isolatedDeclarationErrorsClasses.ts(50,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClasses.ts(56,5): error TS7010: '[noAnnotationLiteralName]', which lacks return-type annotation, implicitly has an 'any' return type. isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -==== isolatedDeclarationErrorsClasses.ts (26 errors) ==== +==== isolatedDeclarationErrorsClasses.ts (20 errors) ==== export class Cls { field = 1 + 1; @@ -87,29 +81,19 @@ isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't b // Should not be reported as an isolated declaration error [missing] = 1; - ~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. ~~~~~~~ !!! error TS2304: Cannot find name 'missing'. [noAnnotationLiteralName](): void { } - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [noParamAnnotationLiteralName](v: string): void { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [noAnnotationStringName]() { } ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. !!! related TS9034 isolatedDeclarationErrorsClasses.ts:42:5: Add a return type to the method - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [noParamAnnotationStringName](v): void { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. ~ !!! error TS7006: Parameter 'v' implicitly has an 'any' type. ~ @@ -117,16 +101,15 @@ isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't b !!! related TS9028 isolatedDeclarationErrorsClasses.ts:44:35: Add a type annotation to the parameter v. get [noAnnotationStringName]() { return 0;} - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. set [noParamAnnotationStringName](value) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7032: Property '[noParamAnnotationStringName]' implicitly has type 'any', because its set accessor lacks a parameter type annotation. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. ~~~~~ !!! error TS7006: Parameter 'value' implicitly has an 'any' type. + ~~~~~ +!!! error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9033 isolatedDeclarationErrorsClasses.ts:48:9: Add a type to parameter of the set accessor declaration. [("A" + "B") as "AB"] = 1; ~~~~~~~~~~~~~~~~~~~~~ diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsObjects.errors.txt b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsObjects.errors.txt index 8fa23907bd2b8..c9ef33a70e1d5 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsObjects.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationErrorsObjects.errors.txt @@ -11,15 +11,12 @@ isolatedDeclarationErrorsObjects.ts(40,25): error TS7006: Parameter 'value' impl 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(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 (16 errors) ==== export let o = { a: 1, b: "" @@ -131,17 +128,8 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp !!! 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 }; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationLazySymbols.errors.txt b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationLazySymbols.errors.txt index 812ec2c1bea83..7ca173df0ca8f 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationLazySymbols.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationLazySymbols.errors.txt @@ -3,10 +3,9 @@ isolatedDeclarationLazySymbols.ts(13,1): error TS9023: Assigning properties to f 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 (5 errors) ==== export function foo() { ~~~ !!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. @@ -41,7 +40,4 @@ isolatedDeclarationLazySymbols.ts(22,5): error TS9038: Computed property names o !!! 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/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js new file mode 100644 index 0000000000000..51a51ba0d27b1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js @@ -0,0 +1,141 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +//// [keys.ts] +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; + +//// [main.ts] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} + + +//// [keys.js] +export const prop = Symbol(); +export const method = Symbol(); +export const accessor = Symbol(); +export const dotted = Symbol(); +export const stringKey = "key"; +export const numberKey = 0; +//// [main.js] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +const localKey = Symbol(); +const literalKey = "literal"; +export class MyClass { + static [keys.method] = true; + [prop] = () => Math.random(); + [keys.dotted] = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey] = 1; + [numberKey] = 1; + [method](value) { return value; } + get [accessor]() { return 1; } + set [accessor](value) { } +} +export const object = { + [prop]: 1, + [keys.method](value) { return value; }, + get [accessor]() { return 1; }, + set [accessor](value) { }, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +}; +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} + + +//// [keys.d.ts] +export declare const prop: unique symbol; +export declare const method: unique symbol; +export declare const accessor: unique symbol; +export declare const dotted: unique symbol; +export declare const stringKey: string; +export declare const numberKey: number; +//// [main.d.ts] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +declare const localKey: unique symbol; +declare const literalKey = "literal"; +export declare class MyClass { + static readonly [keys.method] = true; + [prop]: () => number; + [keys.dotted]: number; + [localKey]: number; + [literalKey]: number; + [stringKey]: number; + [numberKey]: number; + [method](value: number): number; + get [accessor](): number; + set [accessor](value: number); +} +export declare const object: { + [prop]: number; + [keys.method](value: number): number; + get [accessor](): number; + set [accessor](value: number); + [localKey]: boolean; + [literalKey]: string; + [stringKey]: number; + [numberKey]: number; +}; +export declare const readonlyObject: { + readonly [keys.prop]: 1; + readonly nested: { + readonly [localKey]: true; + }; +}; +export declare function makeObject(): { + [keys.prop]: number; + nested: { + [localKey]: boolean; + }; +}; +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols new file mode 100644 index 0000000000000..43c867874e798 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols @@ -0,0 +1,169 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +=== keys.ts === +export const prop: unique symbol = Symbol(); +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const method: unique symbol = Symbol(); +>method : Symbol(method, Decl(keys.ts, 1, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const accessor: unique symbol = Symbol(); +>accessor : Symbol(accessor, Decl(keys.ts, 2, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const dotted: unique symbol = Symbol(); +>dotted : Symbol(dotted, Decl(keys.ts, 3, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const stringKey: string = "key"; +>stringKey : Symbol(stringKey, Decl(keys.ts, 4, 12)) + +export const numberKey: number = 0; +>numberKey : Symbol(numberKey, Decl(keys.ts, 5, 12)) + +=== main.ts === +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +>prop : Symbol(prop, Decl(main.ts, 0, 8)) +>method : Symbol(method, Decl(main.ts, 0, 14)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + +import * as keys from "./keys"; +>keys : Symbol(keys, Decl(main.ts, 1, 6)) + +const localKey: unique symbol = Symbol(); +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const literalKey = "literal"; +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + +export class MyClass { +>MyClass : Symbol(MyClass, Decl(main.ts, 4, 29)) + + static readonly [keys.method] = true; +>[keys.method] : Symbol(MyClass[keys.method], Decl(main.ts, 6, 22)) +>keys.method : Symbol(method, Decl(keys.ts, 1, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>method : Symbol(method, Decl(keys.ts, 1, 12)) + + [prop] = (): number => Math.random(); +>[prop] : Symbol(MyClass[prop], Decl(main.ts, 7, 41)) +>prop : Symbol(prop, Decl(main.ts, 0, 8)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + [keys.dotted]: number = 1; +>[keys.dotted] : Symbol(MyClass[keys.dotted], Decl(main.ts, 8, 41)) +>keys.dotted : Symbol(keys.dotted, Decl(keys.ts, 3, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>dotted : Symbol(keys.dotted, Decl(keys.ts, 3, 12)) + + [localKey] = 1; +>[localKey] : Symbol(MyClass[localKey], Decl(main.ts, 9, 30)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + + [literalKey] = 1; +>[literalKey] : Symbol(MyClass[literalKey], Decl(main.ts, 10, 19)) +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + + [stringKey]: number = 1; +>[stringKey] : Symbol(MyClass[stringKey], Decl(main.ts, 11, 21)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) + + [numberKey]: number = 1; +>[numberKey] : Symbol(MyClass[numberKey], Decl(main.ts, 12, 28)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + + [method](value: number): number { return value; } +>[method] : Symbol(MyClass[method], Decl(main.ts, 13, 28)) +>method : Symbol(method, Decl(main.ts, 0, 14)) +>value : Symbol(value, Decl(main.ts, 14, 13)) +>value : Symbol(value, Decl(main.ts, 14, 13)) + + get [accessor](): number { return 1; } +>[accessor] : Symbol(MyClass[accessor], Decl(main.ts, 14, 53), Decl(main.ts, 15, 42)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) + + set [accessor](value: number) {} +>[accessor] : Symbol(MyClass[accessor], Decl(main.ts, 14, 53), Decl(main.ts, 15, 42)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>value : Symbol(value, Decl(main.ts, 16, 19)) +} + +export const object = { +>object : Symbol(object, Decl(main.ts, 19, 12)) + + [prop]: 1, +>[prop] : Symbol([prop], Decl(main.ts, 19, 23)) +>prop : Symbol(prop, Decl(main.ts, 0, 8)) + + [keys.method](value: number): number { return value; }, +>[keys.method] : Symbol([keys.method], Decl(main.ts, 20, 14)) +>keys.method : Symbol(method, Decl(keys.ts, 1, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>method : Symbol(method, Decl(keys.ts, 1, 12)) +>value : Symbol(value, Decl(main.ts, 21, 18)) +>value : Symbol(value, Decl(main.ts, 21, 18)) + + get [accessor](): number { return 1; }, +>[accessor] : Symbol([accessor], Decl(main.ts, 21, 59), Decl(main.ts, 22, 43)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) + + set [accessor](value: number) {}, +>[accessor] : Symbol([accessor], Decl(main.ts, 21, 59), Decl(main.ts, 22, 43)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>value : Symbol(value, Decl(main.ts, 23, 19)) + + [localKey]: true, +>[localKey] : Symbol([localKey], Decl(main.ts, 23, 37)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + + [literalKey]: "value", +>[literalKey] : Symbol([literalKey], Decl(main.ts, 24, 21)) +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + + [stringKey]: 1, +>[stringKey] : Symbol([stringKey], Decl(main.ts, 25, 26)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) + + [numberKey]: 1, +>[numberKey] : Symbol([numberKey], Decl(main.ts, 26, 19)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + +}; + +export const readonlyObject = { +>readonlyObject : Symbol(readonlyObject, Decl(main.ts, 30, 12)) + + [keys.prop]: 1, +>[keys.prop] : Symbol([keys.prop], Decl(main.ts, 30, 31)) +>keys.prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) + + nested: { [localKey]: true }, +>nested : Symbol(nested, Decl(main.ts, 31, 19)) +>[localKey] : Symbol([localKey], Decl(main.ts, 32, 13)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + +} as const; +>const : Symbol(const) + +export function makeObject() { +>makeObject : Symbol(makeObject, Decl(main.ts, 33, 11)) + + return { [keys.prop]: 1, nested: { [localKey]: true } }; +>[keys.prop] : Symbol([keys.prop], Decl(main.ts, 36, 12)) +>keys.prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>nested : Symbol(nested, Decl(main.ts, 36, 28)) +>[localKey] : Symbol([localKey], Decl(main.ts, 36, 38)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) +} + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types new file mode 100644 index 0000000000000..e3c763da9073c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types @@ -0,0 +1,201 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +=== keys.ts === +export const prop: unique symbol = Symbol(); +>prop : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const method: unique symbol = Symbol(); +>method : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const accessor: unique symbol = Symbol(); +>accessor : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const dotted: unique symbol = Symbol(); +>dotted : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const stringKey: string = "key"; +>stringKey : string +>"key" : "key" + +export const numberKey: number = 0; +>numberKey : number +>0 : 0 + +=== main.ts === +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +>prop : unique symbol +>method : unique symbol +>accessor : unique symbol +>stringKey : string +>numberKey : number + +import * as keys from "./keys"; +>keys : typeof keys + +const localKey: unique symbol = Symbol(); +>localKey : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const literalKey = "literal"; +>literalKey : "literal" +>"literal" : "literal" + +export class MyClass { +>MyClass : MyClass + + static readonly [keys.method] = true; +>[keys.method] : true +>keys.method : unique symbol +>keys : typeof keys +>method : unique symbol +>true : true + + [prop] = (): number => Math.random(); +>[prop] : () => number +>prop : unique symbol +>(): number => Math.random() : () => number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + [keys.dotted]: number = 1; +>[keys.dotted] : number +>keys.dotted : unique symbol +>keys : typeof keys +>dotted : unique symbol +>1 : 1 + + [localKey] = 1; +>[localKey] : number +>localKey : unique symbol +>1 : 1 + + [literalKey] = 1; +>[literalKey] : number +>literalKey : "literal" +>1 : 1 + + [stringKey]: number = 1; +>[stringKey] : number +>stringKey : string +>1 : 1 + + [numberKey]: number = 1; +>[numberKey] : number +>numberKey : number +>1 : 1 + + [method](value: number): number { return value; } +>[method] : (value: number) => number +>method : unique symbol +>value : number +>value : number + + get [accessor](): number { return 1; } +>[accessor] : number +>accessor : unique symbol +>1 : 1 + + set [accessor](value: number) {} +>[accessor] : number +>accessor : unique symbol +>value : number +} + +export const object = { +>object : { [stringKey]: number; [numberKey]: number; [numberKey]: number; [prop]: number; [method](value: number): number; [accessor]: number; [localKey]: boolean; literal: string; } +>{ [prop]: 1, [keys.method](value: number): number { return value; }, get [accessor](): number { return 1; }, set [accessor](value: number) {}, [localKey]: true, [literalKey]: "value", [stringKey]: 1, [numberKey]: 1,} : { [stringKey]: number; [numberKey]: number; [numberKey]: number; [prop]: number; [method](value: number): number; [accessor]: number; [localKey]: boolean; literal: string; } + + [prop]: 1, +>[prop] : number +>prop : unique symbol +>1 : 1 + + [keys.method](value: number): number { return value; }, +>[keys.method] : (value: number) => number +>keys.method : unique symbol +>keys : typeof keys +>method : unique symbol +>value : number +>value : number + + get [accessor](): number { return 1; }, +>[accessor] : number +>accessor : unique symbol +>1 : 1 + + set [accessor](value: number) {}, +>[accessor] : number +>accessor : unique symbol +>value : number + + [localKey]: true, +>[localKey] : boolean +>localKey : unique symbol +>true : true + + [literalKey]: "value", +>[literalKey] : string +>literalKey : "literal" +>"value" : "value" + + [stringKey]: 1, +>[stringKey] : number +>stringKey : string +>1 : 1 + + [numberKey]: 1, +>[numberKey] : number +>numberKey : number +>1 : 1 + +}; + +export const readonlyObject = { +>readonlyObject : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } +>{ [keys.prop]: 1, nested: { [localKey]: true },} as const : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } +>{ [keys.prop]: 1, nested: { [localKey]: true },} : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } + + [keys.prop]: 1, +>[keys.prop] : 1 +>keys.prop : unique symbol +>keys : typeof keys +>prop : unique symbol +>1 : 1 + + nested: { [localKey]: true }, +>nested : { readonly [localKey]: true; } +>{ [localKey]: true } : { readonly [localKey]: true; } +>[localKey] : true +>localKey : unique symbol +>true : true + +} as const; + +export function makeObject() { +>makeObject : () => { [keys.prop]: number; nested: { [localKey]: boolean; }; } + + return { [keys.prop]: 1, nested: { [localKey]: true } }; +>{ [keys.prop]: 1, nested: { [localKey]: true } } : { [prop]: number; nested: { [localKey]: boolean; }; } +>[keys.prop] : number +>keys.prop : unique symbol +>keys : typeof keys +>prop : unique symbol +>1 : 1 +>nested : { [localKey]: boolean; } +>{ [localKey]: true } : { [localKey]: boolean; } +>[localKey] : boolean +>localKey : unique symbol +>true : true +} + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt new file mode 100644 index 0000000000000..87868e5e21a36 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt @@ -0,0 +1,38 @@ +isolatedDeclarationsComputedPropertiesErrors.ts(4,20): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationsComputedPropertiesErrors.ts(5,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +isolatedDeclarationsComputedPropertiesErrors.ts(5,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationsComputedPropertiesErrors.ts(9,13): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationsComputedPropertiesErrors.ts(13,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + + +==== isolatedDeclarationsComputedPropertiesErrors.ts (5 errors) ==== + export const prop: unique symbol = Symbol(); + + export class MyClass { + [prop] = () => Math.random(); + ~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationsComputedPropertiesErrors.ts:4:5: Add a type annotation to the property [prop]. +!!! related TS9035 isolatedDeclarationsComputedPropertiesErrors.ts:4:20: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + ["a" + "b"]: number = 1; + ~~~~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. + } + + export const object = { + [prop]: Math.random(), + ~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationsComputedPropertiesErrors.ts:8:14: Add a type annotation to the variable object. +!!! related TS9035 isolatedDeclarationsComputedPropertiesErrors.ts:9:13: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. + }; + + export const invalidName = { + [Math.random()]: 1, + ~~~~~~~~~~~~~~~ +!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationsComputedPropertiesErrors.ts:12:14: Add a type annotation to the variable invalidName. + }; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js new file mode 100644 index 0000000000000..e1a6aff6b615f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts] //// + +//// [isolatedDeclarationsComputedPropertiesErrors.ts] +export const prop: unique symbol = Symbol(); + +export class MyClass { + [prop] = () => Math.random(); + ["a" + "b"]: number = 1; +} + +export const object = { + [prop]: Math.random(), +}; + +export const invalidName = { + [Math.random()]: 1, +}; + + +//// [isolatedDeclarationsComputedPropertiesErrors.js] +export const prop = Symbol(); +export class MyClass { + [prop] = () => Math.random(); + ["a" + "b"] = 1; +} +export const object = { + [prop]: Math.random(), +}; +export const invalidName = { + [Math.random()]: 1, +}; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols new file mode 100644 index 0000000000000..ae4eab7fb4011 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts] //// + +=== isolatedDeclarationsComputedPropertiesErrors.ts === +export const prop: unique symbol = Symbol(); +>prop : Symbol(prop, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 0, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export class MyClass { +>MyClass : Symbol(MyClass, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 0, 44)) + + [prop] = () => Math.random(); +>[prop] : Symbol(MyClass[prop], Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 2, 22)) +>prop : Symbol(prop, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 0, 12)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + ["a" + "b"]: number = 1; +>["a" + "b"] : Symbol(MyClass["a\" + \"b"], Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 3, 33)) +} + +export const object = { +>object : Symbol(object, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 7, 12)) + + [prop]: Math.random(), +>[prop] : Symbol([prop], Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 7, 23)) +>prop : Symbol(prop, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 0, 12)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +}; + +export const invalidName = { +>invalidName : Symbol(invalidName, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 11, 12)) + + [Math.random()]: 1, +>[Math.random()] : Symbol([Math.random()], Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 11, 28)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +}; + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types new file mode 100644 index 0000000000000..345d53eb432a8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types @@ -0,0 +1,56 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts] //// + +=== isolatedDeclarationsComputedPropertiesErrors.ts === +export const prop: unique symbol = Symbol(); +>prop : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export class MyClass { +>MyClass : MyClass + + [prop] = () => Math.random(); +>[prop] : () => number +>prop : unique symbol +>() => Math.random() : () => number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + ["a" + "b"]: number = 1; +>["a" + "b"] : number +>"a" + "b" : string +>"a" : "a" +>"b" : "b" +>1 : 1 +} + +export const object = { +>object : { [prop]: number; } +>{ [prop]: Math.random(),} : { [prop]: number; } + + [prop]: Math.random(), +>[prop] : number +>prop : unique symbol +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + +}; + +export const invalidName = { +>invalidName : { [x: number]: number; } +>{ [Math.random()]: 1,} : { [x: number]: number; } + + [Math.random()]: 1, +>[Math.random()] : number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>1 : 1 + +}; + diff --git a/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=false).d.ts b/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=false).d.ts index 921b3bd322028..b409294bcc5ae 100644 --- a/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=false).d.ts +++ b/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=false).d.ts @@ -56,6 +56,7 @@ export interface Foo { c?: string; } //// [class.d.ts] //// +declare const i: unique symbol; export declare class Bar { #private; a: string; @@ -65,19 +66,24 @@ export declare class Bar { protected f: string; private g; ["h"]: string; + [i]: string; } export declare abstract class Baz { abstract a: string; abstract method(): void; } +export {}; //// [Diagnostics reported] -class.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +class.ts(1,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. ==== class.ts (1 errors) ==== const i = Symbol(); + ~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 class.ts:1:7: Add a type annotation to the variable i. export class Bar { a: string; b?: string; @@ -88,8 +94,6 @@ class.ts(11,5): error TS9038: Computed property names on class or object literal private g: string; ["h"]: string; [i]: string; - ~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. } export abstract class Baz { diff --git a/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=true).d.ts b/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=true).d.ts index 91fc5c6a76fab..e34c9dcf80a5e 100644 --- a/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=true).d.ts +++ b/tsc/testdata/baselines/reference/transpile/declarationBasicSyntax(declarationMap=true).d.ts @@ -62,6 +62,7 @@ export interface Foo { //// [interface.d.ts.map] //// {"version":3,"file":"interface.d.ts","sources":["interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,CAAC;CACd"} //// [class.d.ts] //// +declare const i: unique symbol; export declare class Bar { #private; a: string; @@ -71,22 +72,27 @@ export declare class Bar { protected f: string; private g; ["h"]: string; + [i]: string; } export declare abstract class Baz { abstract a: string; abstract method(): void; } +export {}; //# sourceMappingURL=class.d.ts.map //// [class.d.ts.map] //// -{"version":3,"file":"class.d.ts","sources":["class.ts"],"names":[],"mappings":"AACA,qBAAa,GAAG;;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;IACH,CAAC,EAAE,MAAM,CAAC;IAEX,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,CAAC,CAAS;IAClB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CAEjB;AAED,8BAAsB,GAAG;IACrB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC;CAC3B"} +{"version":3,"file":"class.d.ts","sources":["class.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,CAAC,eAAW,CAAC;AACnB,qBAAa,GAAG;;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;IACH,CAAC,EAAE,MAAM,CAAC;IAEX,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,CAAC,CAAS;IAClB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;CACf;AAED,8BAAsB,GAAG;IACrB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC;CAC3B"} //// [Diagnostics reported] -class.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +class.ts(1,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. ==== class.ts (1 errors) ==== const i = Symbol(); + ~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 class.ts:1:7: Add a type annotation to the variable i. export class Bar { a: string; b?: string; @@ -97,8 +103,6 @@ class.ts(11,5): error TS9038: Computed property names on class or object literal private g: string; ["h"]: string; [i]: string; - ~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. } export abstract class Baz { diff --git a/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts b/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts index c1259abf658cb..cc466843051bd 100644 --- a/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts +++ b/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts @@ -86,9 +86,12 @@ export interface B { ["2"]: number; } export declare class C { - [x: number]: number; + [missing]: number; + [ns.missing]: number; + [presentNs.a]: number; [Symbol.iterator]: number; [globalThis.Symbol.toStringTag]: number; + [aliasing.isConcatSpreadable]: number; [1]: number; ["2"]: number; } @@ -112,25 +115,15 @@ declarationComputedPropertyNames.ts(18,5): error TS9014: Computed properties mus declarationComputedPropertyNames.ts(27,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. declarationComputedPropertyNames.ts(31,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. declarationComputedPropertyNames.ts(32,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. -declarationComputedPropertyNames.ts(36,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(37,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(38,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(41,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(42,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(45,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(46,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(50,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(51,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(52,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(53,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(54,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(55,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -declarationComputedPropertyNames.ts(56,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(59,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. declarationComputedPropertyNames.ts(60,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -==== declarationComputedPropertyNames.ts (24 errors) ==== +==== declarationComputedPropertyNames.ts (14 errors) ==== export namespace presentNs { export const a = Symbol(); ~ @@ -185,22 +178,14 @@ declarationComputedPropertyNames.ts(60,5): error TS9038: Computed property names export class C { [missing]: number = 1; - ~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [ns.missing]: number = 1; - ~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [presentNs.a]: number = 1; - ~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [Symbol.iterator]: number = 1; [globalThis.Symbol.toStringTag]: number = 1; [(globalThis.Symbol).unscopables]: number = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [aliasing.isConcatSpreadable]: number = 1; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. [1]: number = 1; ["2"]: number = 1; [(missing2)]: number = 1; @@ -213,33 +198,15 @@ declarationComputedPropertyNames.ts(60,5): error TS9038: Computed property names export const D = { [missing]: 1, - ~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [ns.missing]: 1, - ~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [presentNs.a]: 1, - ~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [Symbol.iterator]: 1, - ~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [globalThis.Symbol.toStringTag]: 1, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [(globalThis.Symbol).unscopables]: 1, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. !!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [aliasing.isConcatSpreadable]: 1, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. -!!! related TS9027 declarationComputedPropertyNames.ts:49:14: Add a type annotation to the variable D. [1]: 1, ["2"]: 1, [(missing2)]: 1, diff --git a/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.d.ts b/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.d.ts new file mode 100644 index 0000000000000..27ec6c7eb378e --- /dev/null +++ b/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.d.ts @@ -0,0 +1,93 @@ +//// [keys.ts] //// +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; +//// [main.ts] //// +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} +//// [keys.d.ts] //// +export declare const prop: unique symbol; +export declare const method: unique symbol; +export declare const accessor: unique symbol; +export declare const dotted: unique symbol; +export declare const stringKey: string; +export declare const numberKey: number; +//// [main.d.ts] //// +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +declare const localKey: unique symbol; +declare const literalKey = "literal"; +export declare class MyClass { + static readonly [keys.method] = true; + [prop]: () => number; + [keys.dotted]: number; + [localKey]: number; + [literalKey]: number; + [stringKey]: number; + [numberKey]: number; + [method](value: number): number; + get [accessor](): number; + set [accessor](value: number); +} +export declare const object: { + [prop]: number; + [keys.method](value: number): number; + get [accessor](): number; + set [accessor](value: number); + [localKey]: boolean; + [literalKey]: string; + [stringKey]: number; + [numberKey]: number; +}; +export declare const readonlyObject: { + readonly [keys.prop]: 1; + readonly nested: { + readonly [localKey]: true; + }; +}; +export declare function makeObject(): { + [keys.prop]: number; + nested: { + [localKey]: boolean; + }; +}; +export {}; diff --git a/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.js b/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.js new file mode 100644 index 0000000000000..1b559b770a448 --- /dev/null +++ b/tsc/testdata/baselines/reference/transpile/declarationPreserveComputedProperties.js @@ -0,0 +1,87 @@ +//// [keys.ts] //// +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; +//// [main.ts] //// +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} +//// [keys.js] //// +export const prop = Symbol(); +export const method = Symbol(); +export const accessor = Symbol(); +export const dotted = Symbol(); +export const stringKey = "key"; +export const numberKey = 0; +//// [main.js] //// +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +const localKey = Symbol(); +const literalKey = "literal"; +export class MyClass { + static [keys.method] = true; + [prop] = () => Math.random(); + [keys.dotted] = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey] = 1; + [numberKey] = 1; + [method](value) { return value; } + get [accessor]() { return 1; } + set [accessor](value) { } +} +export const object = { + [prop]: 1, + [keys.method](value) { return value; }, + get [accessor]() { return 1; }, + set [accessor](value) { }, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +}; +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} diff --git a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts new file mode 100644 index 0000000000000..6b4b8276e325f --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts @@ -0,0 +1,52 @@ +// @declaration: true +// @isolatedDeclarations: true +// @strict: true +// @target: esnext + +// @filename: keys.ts +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; + +// @filename: main.ts +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} diff --git a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts new file mode 100644 index 0000000000000..afaa95a8f7706 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts @@ -0,0 +1,19 @@ +// @declaration: true +// @isolatedDeclarations: true +// @strict: true +// @target: esnext + +export const prop: unique symbol = Symbol(); + +export class MyClass { + [prop] = () => Math.random(); + ["a" + "b"]: number = 1; +} + +export const object = { + [prop]: Math.random(), +}; + +export const invalidName = { + [Math.random()]: 1, +}; diff --git a/tsc/testdata/tests/cases/transpile/declarationPreserveComputedProperties.ts b/tsc/testdata/tests/cases/transpile/declarationPreserveComputedProperties.ts new file mode 100644 index 0000000000000..6b4b8276e325f --- /dev/null +++ b/tsc/testdata/tests/cases/transpile/declarationPreserveComputedProperties.ts @@ -0,0 +1,52 @@ +// @declaration: true +// @isolatedDeclarations: true +// @strict: true +// @target: esnext + +// @filename: keys.ts +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; + +// @filename: main.ts +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} From 5ffe833316f2279fffd5271603ba2d37fd3d7289 Mon Sep 17 00:00:00 2001 From: Zyad Haddad <128618322+Trighap52@users.noreply.github.com> Date: Sat, 10 Oct 2026 20:41:12 +0200 Subject: [PATCH 2/2] Keep computed property emit independent of isolatedDeclarations --- tsc/internal/checker/nodebuilderimpl.go | 2 +- tsc/internal/checker/pseudotypenodebuilder.go | 37 ++-- tsc/internal/pseudochecker/checker.go | 5 +- tsc/internal/pseudochecker/lookup.go | 4 +- .../transformers/declarations/transform.go | 30 +-- .../capturedParametersInInitializers1.types | 2 +- ...ssNonUniqueSymbolMethodHasSymbolIndexer.js | 2 +- ...clarationEmitAnyComputedPropertyInClass.js | 2 +- ...rationEmitComputedNameWithQuestionToken.js | 2 +- ...eclarationEmitComputedPropertyNameEnum2.js | 4 +- ...eclarationEmitComputedPropertyNameEnum3.js | 4 +- ...declarationEmitPropertyNumericStringKey.js | 4 +- .../declarationEmitSimpleComputedNames1.js | 10 +- ...ithDefaultAsComputedName(target=es2015).js | 3 +- ...thDefaultAsComputedName2(target=es2015).js | 3 +- .../reference/compiler/dynamicNames.js | 6 +- .../reference/compiler/dynamicNamesErrors.js | 4 +- ...Properties(isolateddeclarations=false).js} | 0 ...rties(isolateddeclarations=false).symbols} | 0 ...perties(isolateddeclarations=false).types} | 0 ...edProperties(isolateddeclarations=true).js | 141 ++++++++++++ ...perties(isolateddeclarations=true).symbols | 169 +++++++++++++++ ...roperties(isolateddeclarations=true).types | 201 ++++++++++++++++++ ...rationsComputedPropertiesErrors.errors.txt | 12 +- ...tedDeclarationsComputedPropertiesErrors.js | 9 + ...clarationsComputedPropertiesErrors.symbols | 15 ++ ...DeclarationsComputedPropertiesErrors.types | 18 ++ ...ctLiteralComputedNameNoDeclarationError.js | 6 +- ...eDynamicName1(noimplicitoverride=false).js | 10 +- ...deDynamicName1(noimplicitoverride=true).js | 10 +- ...dexSignature1(noimplicitoverride=false).js | 10 +- ...ndexSignature1(noimplicitoverride=true).js | 10 +- .../declarationComputedPropertyNames.d.ts | 1 + ...based-projects-and-emits-them-correctly.js | 28 +-- ...zed-module-specifiers-resolve-correctly.js | 28 +-- .../isolatedDeclarationsComputedProperties.ts | 2 +- ...tedDeclarationsComputedPropertiesErrors.ts | 5 + 37 files changed, 696 insertions(+), 103 deletions(-) rename tsc/testdata/baselines/reference/compiler/{isolatedDeclarationsComputedProperties.js => isolatedDeclarationsComputedProperties(isolateddeclarations=false).js} (100%) rename tsc/testdata/baselines/reference/compiler/{isolatedDeclarationsComputedProperties.symbols => isolatedDeclarationsComputedProperties(isolateddeclarations=false).symbols} (100%) rename tsc/testdata/baselines/reference/compiler/{isolatedDeclarationsComputedProperties.types => isolatedDeclarationsComputedProperties(isolateddeclarations=false).types} (100%) create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).js create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).symbols create mode 100644 tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).types diff --git a/tsc/internal/checker/nodebuilderimpl.go b/tsc/internal/checker/nodebuilderimpl.go index 0f4b24962329c..cd4643ac6f273 100644 --- a/tsc/internal/checker/nodebuilderimpl.go +++ b/tsc/internal/checker/nodebuilderimpl.go @@ -127,7 +127,7 @@ func newNodeBuilderImpl(ch *Checker, e *printer.EmitContext, idToSymbol map[*ast if idToSymbol == nil { idToSymbol = make(map[*ast.IdentifierNode]*ast.Symbol) } - b := &NodeBuilderImpl{f: e.Factory.AsNodeFactory(), ch: ch, e: e, idToSymbol: idToSymbol, pc: pseudochecker.NewPseudoChecker(ch.strictNullChecks, ch.exactOptionalPropertyTypes, ch.compilerOptions.IsolatedDeclarations.IsTrue())} + b := &NodeBuilderImpl{f: e.Factory.AsNodeFactory(), ch: ch, e: e, idToSymbol: idToSymbol, pc: pseudochecker.NewPseudoChecker(ch.strictNullChecks, ch.exactOptionalPropertyTypes)} b.cloneBindingNameVisitor = ast.NewNodeVisitor(b.cloneBindingName, b.f, ast.NodeVisitorHooks{}) return b } diff --git a/tsc/internal/checker/pseudotypenodebuilder.go b/tsc/internal/checker/pseudotypenodebuilder.go index 1ebe3b1916624..772ca1495d227 100644 --- a/tsc/internal/checker/pseudotypenodebuilder.go +++ b/tsc/internal/checker/pseudotypenodebuilder.go @@ -421,24 +421,30 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType if type_ == nil { return false } - if b.ch.compilerOptions.IsolatedDeclarations.IsTrue() && core.Some(pt.Elements, func(e *pseudochecker.PseudoObjectElement) bool { - return ast.IsComputedPropertyName(e.Name) && ast.IsEntityNameExpression(e.Name.Expression()) - }) { - // Computed names can resolve to overlapping properties or index signatures. Preserve the - // syntactic members rather than comparing them with the checker's merged object shape. - return true - } targetProps := b.ch.getPropertiesOfType(undefinedStripped) - // Count total declarations across all target prop symbols to handle getter/setter pairs, - // which are two elements in pt.Elements but only one symbol in targetProps. - targetDeclCount := 0 + // Index signature components also represent computed object members. Count each + // declaration once, since a numeric key can contribute to multiple indexes. + targetDeclarations := make(map[*ast.Node]bool) for _, prop := range targetProps { - targetDeclCount += len(prop.Declarations()) + for _, declaration := range prop.Declarations() { + targetDeclarations[declaration] = true + } + } + for _, info := range b.ch.getIndexInfosOfType(undefinedStripped) { + for _, declaration := range info.components { + targetDeclarations[declaration] = true + } } - if len(pt.Elements) != targetDeclCount { + if len(pt.Elements) != len(targetDeclarations) { return false } + hasComputedNames := core.Some(pt.Elements, func(e *pseudochecker.PseudoObjectElement) bool { + return ast.IsComputedPropertyName(e.Name) && ast.IsEntityNameExpression(e.Name.Expression()) + }) for _, e := range pt.Elements { + if ast.IsComputedPropertyName(e.Name) && ast.IsEntityNameExpression(e.Name.Expression()) && !b.isTriviallySerializableComputedName(e.Name.Parent) { + return false + } var targetProp *ast.Symbol elemSymbol := e.Name.Parent.Symbol() if elemSymbol != nil { @@ -448,11 +454,14 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType // Name lookup failed or returned no result; search target properties // for one whose declaration name node matches the one we have for _, prop := range targetProps { - if prop.ValueDeclaration() != nil && prop.ValueDeclaration().Name() == e.Name { + if core.Some(prop.Declarations(), func(d *ast.Node) bool { return d.Name() == e.Name }) { targetProp = prop break } } + if targetProp == nil && targetDeclarations[e.Name.Parent] && undefinedStripped.objectFlags&ObjectFlagsInstantiated == 0 { + targetProp = b.ch.getSymbolOfDeclaration(e.Name.Parent) + } if targetProp == nil { if reportErrors { b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) @@ -472,7 +481,7 @@ 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 hasComputedNames && d.Type.Kind == pseudochecker.PseudoTypeKindInferred && len(d.Type.AsPseudoTypeInferred().ErrorNodes) > 0 || !b.pseudoTypeEquivalentToType(d.Type, propType, e.Optional, false) { if reportErrors { if d.Type.Kind == pseudochecker.PseudoTypeKindInferred && len(d.Type.AsPseudoTypeInferred().ErrorNodes) > 0 { // Re-report the fine-grained error nodes; the recursive call used reportErrors=false diff --git a/tsc/internal/pseudochecker/checker.go b/tsc/internal/pseudochecker/checker.go index 4f074d8eb1820..b9baa07f40ba8 100644 --- a/tsc/internal/pseudochecker/checker.go +++ b/tsc/internal/pseudochecker/checker.go @@ -14,9 +14,8 @@ package pseudochecker type PseudoChecker struct { strictNullChecks bool exactOptionalPropertyTypes bool - preserveComputedNames bool } -func NewPseudoChecker(strictNullChecks bool, exactOptionalPropertyTypes bool, preserveComputedNames bool) *PseudoChecker { - return &PseudoChecker{strictNullChecks: strictNullChecks, exactOptionalPropertyTypes: exactOptionalPropertyTypes, preserveComputedNames: preserveComputedNames} +func NewPseudoChecker(strictNullChecks bool, exactOptionalPropertyTypes bool) *PseudoChecker { + return &PseudoChecker{strictNullChecks: strictNullChecks, exactOptionalPropertyTypes: exactOptionalPropertyTypes} } diff --git a/tsc/internal/pseudochecker/lookup.go b/tsc/internal/pseudochecker/lookup.go index b53c382ca9d67..4cf3623103219 100644 --- a/tsc/internal/pseudochecker/lookup.go +++ b/tsc/internal/pseudochecker/lookup.go @@ -361,7 +361,7 @@ func (ch *PseudoChecker) typeFromObjectLiteral(node *ast.ObjectLiteralExpression // roughly analogous to typeFromObjectLiteralAccessor in strada func (ch *PseudoChecker) getAccessorMember(accessor *ast.Node, name *ast.Node) *PseudoObjectElement { - if ch.preserveComputedNames && ast.IsComputedPropertyName(name) && ast.IsEntityNameExpression(name.Expression()) { + if ast.IsComputedPropertyName(name) && ast.IsEntityNameExpression(name.Expression()) { // Computed accessors cannot be paired using their bound symbols alone. Preserve each // accessor so the declaration checker can resolve the computed names and pair them. if ast.IsGetAccessorDeclaration(accessor) { @@ -435,7 +435,7 @@ func (ch *PseudoChecker) canGetTypeFromObjectLiteral(node *ast.ObjectLiteralExpr } if e.Name().Kind == ast.KindComputedPropertyName { expression := e.Name().Expression() - if !ast.IsPrimitiveLiteralValue(expression, false) && !(ch.preserveComputedNames && ast.IsEntityNameExpression(expression)) { + if !ast.IsPrimitiveLiteralValue(expression, false) && !ast.IsEntityNameExpression(expression) { errorNodes = append(errorNodes, e.Name()) } } diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 06d9592702334..4c4507979e7a5 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -585,7 +585,8 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast. return nil } } - } else if !tx.resolver.IsLateBound(tx.EmitContext().ParseNode(input)) || !ast.IsEntityNameExpression(input.Name().Expression()) { + } + if !ast.IsEntityNameExpression(input.Name().Expression()) { return nil } } @@ -1964,24 +1965,25 @@ func (tx *DeclarationTransformer) buildClassMembers(classNode *ast.Node, extraMe privateIdentifier = tx.Factory().NewPropertyDeclaration(nil, tx.Factory().NewPrivateIdentifier("#private"), nil, nil, nil) } - var lateIndexes []*ast.Node - if !tx.state.isolatedDeclarations { - // Isolated declaration emit preserves the computed members themselves, so their - // inferred index signatures must not add another copy of those members. - lateIndexes = tx.resolver.CreateLateBoundIndexSignatures( - classNode, - tx.enclosingDeclaration, - declarationEmitNodeBuilderFlags, - declarationEmitInternalNodeBuilderFlags, - tx.tracker, - ) - } + lateIndexes := tx.resolver.CreateLateBoundIndexSignatures( + classNode, + tx.enclosingDeclaration, + declarationEmitNodeBuilderFlags, + declarationEmitInternalNodeBuilderFlags, + tx.tracker, + ) memberNodes := make([]*ast.Node, 0, len(classNode.ClassLikeData().Members.Nodes)) if privateIdentifier != nil { memberNodes = append(memberNodes, privateIdentifier) } - memberNodes = append(memberNodes, lateIndexes...) + // Entity computed names are emitted from the original class members below. + // Keep synthesized indexes only when they do not duplicate those members. + for _, index := range lateIndexes { + if index.Name() == nil || !ast.IsComputedPropertyName(index.Name()) || !ast.IsEntityNameExpression(index.Name().Expression()) { + memberNodes = append(memberNodes, index) + } + } memberNodes = append(memberNodes, parameterProperties...) memberNodes = append(memberNodes, extraMembers...) visitResult := tx.Visitor().VisitNodes(classNode.ClassLikeData().Members) diff --git a/tsc/testdata/baselines/reference/compiler/capturedParametersInInitializers1.types b/tsc/testdata/baselines/reference/compiler/capturedParametersInInitializers1.types index 787226d27da15..34c8479ad4b7b 100644 --- a/tsc/testdata/baselines/reference/compiler/capturedParametersInInitializers1.types +++ b/tsc/testdata/baselines/reference/compiler/capturedParametersInInitializers1.types @@ -109,7 +109,7 @@ function foo8(y = (async () => z)(), z = 1) { // error - used as computed name of method function foo9(y = {[z]() { return z; }}, z = 1) { ->foo9 : (y?: { [z]: () => number; }, z?: number) => void +>foo9 : (y?: { [z](): number; }, z?: number) => void >y : { [z]: () => number; } >{[z]() { return z; }} : { [z]: () => number; } >[z] : () => number diff --git a/tsc/testdata/baselines/reference/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.js b/tsc/testdata/baselines/reference/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.js index 87e6bdcbef296..5e6a1409b678b 100644 --- a/tsc/testdata/baselines/reference/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.js +++ b/tsc/testdata/baselines/reference/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.js @@ -29,7 +29,7 @@ export const Mixer = Mix(class { //// [classNonUniqueSymbolMethodHasSymbolIndexer.d.ts] declare const a: symbol; export declare class A { - [a]: () => number; + [a](): number; } export declare const Mixer: { new (): { diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitAnyComputedPropertyInClass.js b/tsc/testdata/baselines/reference/compiler/declarationEmitAnyComputedPropertyInClass.js index 0247a9743c5f9..24c3c6d55f6dc 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitAnyComputedPropertyInClass.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitAnyComputedPropertyInClass.js @@ -29,5 +29,5 @@ exports.C = C; //// [main.d.ts] import Test from "abcdefgh"; export declare class C { - [Test.someKey]: () => void; + [Test.someKey](): void; } diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedNameWithQuestionToken.js b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedNameWithQuestionToken.js index f0071ca8d8d35..7282c2172b9f9 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedNameWithQuestionToken.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedNameWithQuestionToken.js @@ -29,6 +29,6 @@ exports.a = (new WithData())["ahahahaahah"](); //// [declarationEmitComputedNameWithQuestionToken.d.ts] export declare const dataSomething: `data-${string}`; export declare class WithData { - [dataSomething]?: (() => string) | undefined; + [dataSomething]?(): string; } export declare const a: string; diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum2.js b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum2.js index c77d5998d8705..94415e9becd7b 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum2.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum2.js @@ -13,7 +13,9 @@ export const foo = { ...({} as Type) }; //// [type.d.ts] export type Type = { - x?: {}; + x?: { + [Enum.A]: 0; + }; }; //// [index.d.ts] export declare const foo: { diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum3.js b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum3.js index 1e3f52a3eafeb..24b0dd5f96654 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum3.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitComputedPropertyNameEnum3.js @@ -25,7 +25,9 @@ export declare namespace Foo { } } export type Type = { - x?: {}; + x?: { + [Foo.Enum]: 0; + }; }; //// [index.d.ts] export declare const foo: { diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitPropertyNumericStringKey.js b/tsc/testdata/baselines/reference/compiler/declarationEmitPropertyNumericStringKey.js index dde7b3e1a6161..3668d075817da 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitPropertyNumericStringKey.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitPropertyNumericStringKey.js @@ -32,9 +32,9 @@ declare const STATUS: { }; declare const hundredStr = "100"; declare const obj: { - "100": string; + [hundredStr]: string; }; declare const hundredNum = 100; declare const obj2: { - 100: string; + [hundredNum]: string; }; diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitSimpleComputedNames1.js b/tsc/testdata/baselines/reference/compiler/declarationEmitSimpleComputedNames1.js index 317aaefcdc557..b27fb0233d96e 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitSimpleComputedNames1.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitSimpleComputedNames1.js @@ -71,20 +71,20 @@ exports.instanceLookup = (new Holder())["some" + "thing"]; //// [declarationEmitSimpleComputedNames1.d.ts] export declare const fieldName: string; export declare const conatainer: { - [fieldName]: () => string; + [fieldName](): string; }; declare const classFieldName: string; declare const otherField: string; declare const staticField: string; export declare class Holder { - static [staticField]: () => { + [classFieldName](): string; + [otherField](): number; + static [staticField](): { static: boolean; }; - static [staticField]: () => { + static [staticField](): { static: string; }; - [classFieldName]: () => string; - [otherField]: () => number; } /** * Could be `"prototype"`, so all static string indexers include the instance type diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName(target=es2015).js b/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName(target=es2015).js index ad6cdb16f5e6f..5b81fd44362f8 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName(target=es2015).js @@ -43,6 +43,7 @@ type Experiment = { declare const _default: Experiment<"foo">; export default _default; //// [main.d.ts] +import other from "./other"; export declare const obj: { - foo: number; + [other.name]: number; }; diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName2(target=es2015).js b/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName2(target=es2015).js index 30de49c1993db..5df0a70b0c1ec 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName2(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitWithDefaultAsComputedName2(target=es2015).js @@ -73,6 +73,7 @@ type Experiment = { declare const _default: Experiment<"foo">; export default _default; //// [main.d.ts] +import * as other2 from "./other"; export declare const obj: { - foo: number; + [other2.default.name]: number; }; diff --git a/tsc/testdata/baselines/reference/compiler/dynamicNames.js b/tsc/testdata/baselines/reference/compiler/dynamicNames.js index 14ae09b401ba1..aa5417b8201cf 100644 --- a/tsc/testdata/baselines/reference/compiler/dynamicNames.js +++ b/tsc/testdata/baselines/reference/compiler/dynamicNames.js @@ -242,9 +242,9 @@ export declare const c4 = "a"; export declare const c5 = 1; export declare const s2: typeof s0; export declare const o1: { - a: number; - 1: string; - [s0]: boolean; + [c4]: number; + [c5]: string; + [s2]: boolean; }; export declare const o1_c4: number; export declare const o1_c5: string; diff --git a/tsc/testdata/baselines/reference/compiler/dynamicNamesErrors.js b/tsc/testdata/baselines/reference/compiler/dynamicNamesErrors.js index 2a67b990b13f6..e08f4ee498eac 100644 --- a/tsc/testdata/baselines/reference/compiler/dynamicNamesErrors.js +++ b/tsc/testdata/baselines/reference/compiler/dynamicNamesErrors.js @@ -116,7 +116,7 @@ export type ObjectTypeVisibility = { export declare const ObjectLiteralVisibility: { [x]: number; [y](): number; - readonly [z]: number; - [w]: number; + get [z](): number; + set [w](value: number); }; export {}; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).js similarity index 100% rename from tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.js rename to tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).js diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).symbols similarity index 100% rename from tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.symbols rename to tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).symbols diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).types similarity index 100% rename from tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties.types rename to tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=false).types diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).js b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).js new file mode 100644 index 0000000000000..51a51ba0d27b1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).js @@ -0,0 +1,141 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +//// [keys.ts] +export const prop: unique symbol = Symbol(); +export const method: unique symbol = Symbol(); +export const accessor: unique symbol = Symbol(); +export const dotted: unique symbol = Symbol(); +export const stringKey: string = "key"; +export const numberKey: number = 0; + +//// [main.ts] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; + +const localKey: unique symbol = Symbol(); +const literalKey = "literal"; + +export class MyClass { + static readonly [keys.method] = true; + [prop] = (): number => Math.random(); + [keys.dotted]: number = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey]: number = 1; + [numberKey]: number = 1; + [method](value: number): number { return value; } + get [accessor](): number { return 1; } + set [accessor](value: number) {} +} + +export const object = { + [prop]: 1, + [keys.method](value: number): number { return value; }, + get [accessor](): number { return 1; }, + set [accessor](value: number) {}, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; + +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +} as const; + +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} + + +//// [keys.js] +export const prop = Symbol(); +export const method = Symbol(); +export const accessor = Symbol(); +export const dotted = Symbol(); +export const stringKey = "key"; +export const numberKey = 0; +//// [main.js] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +const localKey = Symbol(); +const literalKey = "literal"; +export class MyClass { + static [keys.method] = true; + [prop] = () => Math.random(); + [keys.dotted] = 1; + [localKey] = 1; + [literalKey] = 1; + [stringKey] = 1; + [numberKey] = 1; + [method](value) { return value; } + get [accessor]() { return 1; } + set [accessor](value) { } +} +export const object = { + [prop]: 1, + [keys.method](value) { return value; }, + get [accessor]() { return 1; }, + set [accessor](value) { }, + [localKey]: true, + [literalKey]: "value", + [stringKey]: 1, + [numberKey]: 1, +}; +export const readonlyObject = { + [keys.prop]: 1, + nested: { [localKey]: true }, +}; +export function makeObject() { + return { [keys.prop]: 1, nested: { [localKey]: true } }; +} + + +//// [keys.d.ts] +export declare const prop: unique symbol; +export declare const method: unique symbol; +export declare const accessor: unique symbol; +export declare const dotted: unique symbol; +export declare const stringKey: string; +export declare const numberKey: number; +//// [main.d.ts] +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +import * as keys from "./keys"; +declare const localKey: unique symbol; +declare const literalKey = "literal"; +export declare class MyClass { + static readonly [keys.method] = true; + [prop]: () => number; + [keys.dotted]: number; + [localKey]: number; + [literalKey]: number; + [stringKey]: number; + [numberKey]: number; + [method](value: number): number; + get [accessor](): number; + set [accessor](value: number); +} +export declare const object: { + [prop]: number; + [keys.method](value: number): number; + get [accessor](): number; + set [accessor](value: number); + [localKey]: boolean; + [literalKey]: string; + [stringKey]: number; + [numberKey]: number; +}; +export declare const readonlyObject: { + readonly [keys.prop]: 1; + readonly nested: { + readonly [localKey]: true; + }; +}; +export declare function makeObject(): { + [keys.prop]: number; + nested: { + [localKey]: boolean; + }; +}; +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).symbols b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).symbols new file mode 100644 index 0000000000000..43c867874e798 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).symbols @@ -0,0 +1,169 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +=== keys.ts === +export const prop: unique symbol = Symbol(); +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const method: unique symbol = Symbol(); +>method : Symbol(method, Decl(keys.ts, 1, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const accessor: unique symbol = Symbol(); +>accessor : Symbol(accessor, Decl(keys.ts, 2, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const dotted: unique symbol = Symbol(); +>dotted : Symbol(dotted, Decl(keys.ts, 3, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +export const stringKey: string = "key"; +>stringKey : Symbol(stringKey, Decl(keys.ts, 4, 12)) + +export const numberKey: number = 0; +>numberKey : Symbol(numberKey, Decl(keys.ts, 5, 12)) + +=== main.ts === +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +>prop : Symbol(prop, Decl(main.ts, 0, 8)) +>method : Symbol(method, Decl(main.ts, 0, 14)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + +import * as keys from "./keys"; +>keys : Symbol(keys, Decl(main.ts, 1, 6)) + +const localKey: unique symbol = Symbol(); +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const literalKey = "literal"; +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + +export class MyClass { +>MyClass : Symbol(MyClass, Decl(main.ts, 4, 29)) + + static readonly [keys.method] = true; +>[keys.method] : Symbol(MyClass[keys.method], Decl(main.ts, 6, 22)) +>keys.method : Symbol(method, Decl(keys.ts, 1, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>method : Symbol(method, Decl(keys.ts, 1, 12)) + + [prop] = (): number => Math.random(); +>[prop] : Symbol(MyClass[prop], Decl(main.ts, 7, 41)) +>prop : Symbol(prop, Decl(main.ts, 0, 8)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + [keys.dotted]: number = 1; +>[keys.dotted] : Symbol(MyClass[keys.dotted], Decl(main.ts, 8, 41)) +>keys.dotted : Symbol(keys.dotted, Decl(keys.ts, 3, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>dotted : Symbol(keys.dotted, Decl(keys.ts, 3, 12)) + + [localKey] = 1; +>[localKey] : Symbol(MyClass[localKey], Decl(main.ts, 9, 30)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + + [literalKey] = 1; +>[literalKey] : Symbol(MyClass[literalKey], Decl(main.ts, 10, 19)) +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + + [stringKey]: number = 1; +>[stringKey] : Symbol(MyClass[stringKey], Decl(main.ts, 11, 21)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) + + [numberKey]: number = 1; +>[numberKey] : Symbol(MyClass[numberKey], Decl(main.ts, 12, 28)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + + [method](value: number): number { return value; } +>[method] : Symbol(MyClass[method], Decl(main.ts, 13, 28)) +>method : Symbol(method, Decl(main.ts, 0, 14)) +>value : Symbol(value, Decl(main.ts, 14, 13)) +>value : Symbol(value, Decl(main.ts, 14, 13)) + + get [accessor](): number { return 1; } +>[accessor] : Symbol(MyClass[accessor], Decl(main.ts, 14, 53), Decl(main.ts, 15, 42)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) + + set [accessor](value: number) {} +>[accessor] : Symbol(MyClass[accessor], Decl(main.ts, 14, 53), Decl(main.ts, 15, 42)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>value : Symbol(value, Decl(main.ts, 16, 19)) +} + +export const object = { +>object : Symbol(object, Decl(main.ts, 19, 12)) + + [prop]: 1, +>[prop] : Symbol([prop], Decl(main.ts, 19, 23)) +>prop : Symbol(prop, Decl(main.ts, 0, 8)) + + [keys.method](value: number): number { return value; }, +>[keys.method] : Symbol([keys.method], Decl(main.ts, 20, 14)) +>keys.method : Symbol(method, Decl(keys.ts, 1, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>method : Symbol(method, Decl(keys.ts, 1, 12)) +>value : Symbol(value, Decl(main.ts, 21, 18)) +>value : Symbol(value, Decl(main.ts, 21, 18)) + + get [accessor](): number { return 1; }, +>[accessor] : Symbol([accessor], Decl(main.ts, 21, 59), Decl(main.ts, 22, 43)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) + + set [accessor](value: number) {}, +>[accessor] : Symbol([accessor], Decl(main.ts, 21, 59), Decl(main.ts, 22, 43)) +>accessor : Symbol(accessor, Decl(main.ts, 0, 22)) +>value : Symbol(value, Decl(main.ts, 23, 19)) + + [localKey]: true, +>[localKey] : Symbol([localKey], Decl(main.ts, 23, 37)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + + [literalKey]: "value", +>[literalKey] : Symbol([literalKey], Decl(main.ts, 24, 21)) +>literalKey : Symbol(literalKey, Decl(main.ts, 4, 5)) + + [stringKey]: 1, +>[stringKey] : Symbol([stringKey], Decl(main.ts, 25, 26)) +>stringKey : Symbol(stringKey, Decl(main.ts, 0, 32)) + + [numberKey]: 1, +>[numberKey] : Symbol([numberKey], Decl(main.ts, 26, 19)) +>numberKey : Symbol(numberKey, Decl(main.ts, 0, 43)) + +}; + +export const readonlyObject = { +>readonlyObject : Symbol(readonlyObject, Decl(main.ts, 30, 12)) + + [keys.prop]: 1, +>[keys.prop] : Symbol([keys.prop], Decl(main.ts, 30, 31)) +>keys.prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) + + nested: { [localKey]: true }, +>nested : Symbol(nested, Decl(main.ts, 31, 19)) +>[localKey] : Symbol([localKey], Decl(main.ts, 32, 13)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) + +} as const; +>const : Symbol(const) + +export function makeObject() { +>makeObject : Symbol(makeObject, Decl(main.ts, 33, 11)) + + return { [keys.prop]: 1, nested: { [localKey]: true } }; +>[keys.prop] : Symbol([keys.prop], Decl(main.ts, 36, 12)) +>keys.prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>keys : Symbol(keys, Decl(main.ts, 1, 6)) +>prop : Symbol(prop, Decl(keys.ts, 0, 12)) +>nested : Symbol(nested, Decl(main.ts, 36, 28)) +>[localKey] : Symbol([localKey], Decl(main.ts, 36, 38)) +>localKey : Symbol(localKey, Decl(main.ts, 3, 5)) +} + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).types b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).types new file mode 100644 index 0000000000000..e3c763da9073c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedProperties(isolateddeclarations=true).types @@ -0,0 +1,201 @@ +//// [tests/cases/compiler/isolatedDeclarationsComputedProperties.ts] //// + +=== keys.ts === +export const prop: unique symbol = Symbol(); +>prop : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const method: unique symbol = Symbol(); +>method : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const accessor: unique symbol = Symbol(); +>accessor : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const dotted: unique symbol = Symbol(); +>dotted : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const stringKey: string = "key"; +>stringKey : string +>"key" : "key" + +export const numberKey: number = 0; +>numberKey : number +>0 : 0 + +=== main.ts === +import { prop, method, accessor, stringKey, numberKey } from "./keys"; +>prop : unique symbol +>method : unique symbol +>accessor : unique symbol +>stringKey : string +>numberKey : number + +import * as keys from "./keys"; +>keys : typeof keys + +const localKey: unique symbol = Symbol(); +>localKey : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const literalKey = "literal"; +>literalKey : "literal" +>"literal" : "literal" + +export class MyClass { +>MyClass : MyClass + + static readonly [keys.method] = true; +>[keys.method] : true +>keys.method : unique symbol +>keys : typeof keys +>method : unique symbol +>true : true + + [prop] = (): number => Math.random(); +>[prop] : () => number +>prop : unique symbol +>(): number => Math.random() : () => number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + [keys.dotted]: number = 1; +>[keys.dotted] : number +>keys.dotted : unique symbol +>keys : typeof keys +>dotted : unique symbol +>1 : 1 + + [localKey] = 1; +>[localKey] : number +>localKey : unique symbol +>1 : 1 + + [literalKey] = 1; +>[literalKey] : number +>literalKey : "literal" +>1 : 1 + + [stringKey]: number = 1; +>[stringKey] : number +>stringKey : string +>1 : 1 + + [numberKey]: number = 1; +>[numberKey] : number +>numberKey : number +>1 : 1 + + [method](value: number): number { return value; } +>[method] : (value: number) => number +>method : unique symbol +>value : number +>value : number + + get [accessor](): number { return 1; } +>[accessor] : number +>accessor : unique symbol +>1 : 1 + + set [accessor](value: number) {} +>[accessor] : number +>accessor : unique symbol +>value : number +} + +export const object = { +>object : { [stringKey]: number; [numberKey]: number; [numberKey]: number; [prop]: number; [method](value: number): number; [accessor]: number; [localKey]: boolean; literal: string; } +>{ [prop]: 1, [keys.method](value: number): number { return value; }, get [accessor](): number { return 1; }, set [accessor](value: number) {}, [localKey]: true, [literalKey]: "value", [stringKey]: 1, [numberKey]: 1,} : { [stringKey]: number; [numberKey]: number; [numberKey]: number; [prop]: number; [method](value: number): number; [accessor]: number; [localKey]: boolean; literal: string; } + + [prop]: 1, +>[prop] : number +>prop : unique symbol +>1 : 1 + + [keys.method](value: number): number { return value; }, +>[keys.method] : (value: number) => number +>keys.method : unique symbol +>keys : typeof keys +>method : unique symbol +>value : number +>value : number + + get [accessor](): number { return 1; }, +>[accessor] : number +>accessor : unique symbol +>1 : 1 + + set [accessor](value: number) {}, +>[accessor] : number +>accessor : unique symbol +>value : number + + [localKey]: true, +>[localKey] : boolean +>localKey : unique symbol +>true : true + + [literalKey]: "value", +>[literalKey] : string +>literalKey : "literal" +>"value" : "value" + + [stringKey]: 1, +>[stringKey] : number +>stringKey : string +>1 : 1 + + [numberKey]: 1, +>[numberKey] : number +>numberKey : number +>1 : 1 + +}; + +export const readonlyObject = { +>readonlyObject : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } +>{ [keys.prop]: 1, nested: { [localKey]: true },} as const : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } +>{ [keys.prop]: 1, nested: { [localKey]: true },} : { readonly [prop]: 1; readonly nested: { readonly [localKey]: true; }; } + + [keys.prop]: 1, +>[keys.prop] : 1 +>keys.prop : unique symbol +>keys : typeof keys +>prop : unique symbol +>1 : 1 + + nested: { [localKey]: true }, +>nested : { readonly [localKey]: true; } +>{ [localKey]: true } : { readonly [localKey]: true; } +>[localKey] : true +>localKey : unique symbol +>true : true + +} as const; + +export function makeObject() { +>makeObject : () => { [keys.prop]: number; nested: { [localKey]: boolean; }; } + + return { [keys.prop]: 1, nested: { [localKey]: true } }; +>{ [keys.prop]: 1, nested: { [localKey]: true } } : { [prop]: number; nested: { [localKey]: boolean; }; } +>[keys.prop] : number +>keys.prop : unique symbol +>keys : typeof keys +>prop : unique symbol +>1 : 1 +>nested : { [localKey]: boolean; } +>{ [localKey]: true } : { [localKey]: boolean; } +>[localKey] : boolean +>localKey : unique symbol +>true : true +} + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt index 87868e5e21a36..6f95766ebf06c 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.errors.txt @@ -3,9 +3,10 @@ isolatedDeclarationsComputedPropertiesErrors.ts(5,5): error TS1166: A computed p isolatedDeclarationsComputedPropertiesErrors.ts(5,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. isolatedDeclarationsComputedPropertiesErrors.ts(9,13): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationsComputedPropertiesErrors.ts(13,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. +isolatedDeclarationsComputedPropertiesErrors.ts(18,18): error TS9013: Expression type can't be inferred with --isolatedDeclarations. -==== isolatedDeclarationsComputedPropertiesErrors.ts (5 errors) ==== +==== isolatedDeclarationsComputedPropertiesErrors.ts (6 errors) ==== export const prop: unique symbol = Symbol(); export class MyClass { @@ -35,4 +36,13 @@ isolatedDeclarationsComputedPropertiesErrors.ts(13,5): error TS9038: Computed pr !!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationsComputedPropertiesErrors.ts:12:14: Add a type annotation to the variable invalidName. }; + + export const stringKey: string = "key"; + export const indexedObject = { + [stringKey]: Math.random(), + ~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationsComputedPropertiesErrors.ts:17:14: Add a type annotation to the variable indexedObject. +!!! related TS9035 isolatedDeclarationsComputedPropertiesErrors.ts:18:18: 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/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js index e1a6aff6b615f..9a0156aa52644 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.js @@ -15,6 +15,11 @@ export const object = { export const invalidName = { [Math.random()]: 1, }; + +export const stringKey: string = "key"; +export const indexedObject = { + [stringKey]: Math.random(), +}; //// [isolatedDeclarationsComputedPropertiesErrors.js] @@ -29,3 +34,7 @@ export const object = { export const invalidName = { [Math.random()]: 1, }; +export const stringKey = "key"; +export const indexedObject = { + [stringKey]: Math.random(), +}; diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols index ae4eab7fb4011..e0d3949763a66 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.symbols @@ -42,3 +42,18 @@ export const invalidName = { }; +export const stringKey: string = "key"; +>stringKey : Symbol(stringKey, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 15, 12)) + +export const indexedObject = { +>indexedObject : Symbol(indexedObject, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 16, 12)) + + [stringKey]: Math.random(), +>[stringKey] : Symbol([stringKey], Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 16, 30)) +>stringKey : Symbol(stringKey, Decl(isolatedDeclarationsComputedPropertiesErrors.ts, 15, 12)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --) ... and 1 more) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +}; + diff --git a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types index 345d53eb432a8..558cdf3d8b5ac 100644 --- a/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types +++ b/tsc/testdata/baselines/reference/compiler/isolatedDeclarationsComputedPropertiesErrors.types @@ -54,3 +54,21 @@ export const invalidName = { }; +export const stringKey: string = "key"; +>stringKey : string +>"key" : "key" + +export const indexedObject = { +>indexedObject : { [stringKey]: number; } +>{ [stringKey]: Math.random(),} : { [stringKey]: number; } + + [stringKey]: Math.random(), +>[stringKey] : number +>stringKey : string +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + +}; + diff --git a/tsc/testdata/baselines/reference/compiler/objectLiteralComputedNameNoDeclarationError.js b/tsc/testdata/baselines/reference/compiler/objectLiteralComputedNameNoDeclarationError.js index 38e2e49e76a82..51a419f8078d4 100644 --- a/tsc/testdata/baselines/reference/compiler/objectLiteralComputedNameNoDeclarationError.js +++ b/tsc/testdata/baselines/reference/compiler/objectLiteralComputedNameNoDeclarationError.js @@ -19,6 +19,10 @@ export const Baa = { //// [objectLiteralComputedNameNoDeclarationError.d.ts] +declare const Foo: { + BANANA: 'banana'; +}; export declare const Baa: { - banana: number; + [Foo.BANANA]: number; }; +export {}; diff --git a/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=false).js b/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=false).js index 22e2a11cfe682..94911e9b5b9d3 100644 --- a/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=false).js +++ b/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=false).js @@ -31,19 +31,19 @@ class Derived3 extends Base3 { //// [overrideDynamicName1.d.ts] declare let prop: string; declare class Base1 { - [prop]: () => void; + [prop](): void; } declare class Derived1 extends Base1 { - [prop]: () => void; + [prop](): void; } declare class Base2 { - [prop]: () => void; + [prop](): void; } declare class Derived2 extends Base2 { - [prop]: () => void; + [prop](): void; } declare class Base3 { } declare class Derived3 extends Base3 { - [prop]: () => void; + [prop](): void; } diff --git a/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=true).js b/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=true).js index 22e2a11cfe682..94911e9b5b9d3 100644 --- a/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=true).js +++ b/tsc/testdata/baselines/reference/conformance/overrideDynamicName1(noimplicitoverride=true).js @@ -31,19 +31,19 @@ class Derived3 extends Base3 { //// [overrideDynamicName1.d.ts] declare let prop: string; declare class Base1 { - [prop]: () => void; + [prop](): void; } declare class Derived1 extends Base1 { - [prop]: () => void; + [prop](): void; } declare class Base2 { - [prop]: () => void; + [prop](): void; } declare class Derived2 extends Base2 { - [prop]: () => void; + [prop](): void; } declare class Base3 { } declare class Derived3 extends Base3 { - [prop]: () => void; + [prop](): void; } diff --git a/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=false).js b/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=false).js index 17d12eb6de30e..7a532a0cf8232 100644 --- a/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=false).js +++ b/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=false).js @@ -31,19 +31,19 @@ class Derived3 extends Base3 { //// [overrideLateBindableIndexSignature1.d.ts] declare const sym: symbol; declare class Base1 { - [sym]: () => void; + [sym](): void; } declare class Derived1 extends Base1 { - [sym]: () => void; + [sym](): void; } declare class Base2 { - [sym]: () => void; + [sym](): void; } declare class Derived2 extends Base2 { - [sym]: () => void; + [sym](): void; } declare class Base3 { } declare class Derived3 extends Base3 { - [sym]: () => void; + [sym](): void; } diff --git a/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=true).js b/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=true).js index 17d12eb6de30e..7a532a0cf8232 100644 --- a/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=true).js +++ b/tsc/testdata/baselines/reference/conformance/overrideLateBindableIndexSignature1(noimplicitoverride=true).js @@ -31,19 +31,19 @@ class Derived3 extends Base3 { //// [overrideLateBindableIndexSignature1.d.ts] declare const sym: symbol; declare class Base1 { - [sym]: () => void; + [sym](): void; } declare class Derived1 extends Base1 { - [sym]: () => void; + [sym](): void; } declare class Base2 { - [sym]: () => void; + [sym](): void; } declare class Derived2 extends Base2 { - [sym]: () => void; + [sym](): void; } declare class Base3 { } declare class Derived3 extends Base3 { - [sym]: () => void; + [sym](): void; } diff --git a/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts b/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts index cc466843051bd..26048476e7d3f 100644 --- a/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts +++ b/tsc/testdata/baselines/reference/transpile/declarationComputedPropertyNames.d.ts @@ -86,6 +86,7 @@ export interface B { ["2"]: number; } export declare class C { + [x: number]: number; [missing]: number; [ns.missing]: number; [presentNs.a]: number; diff --git a/tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js b/tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js index c06e1dfa34050..b7b016f892106 100644 --- a/tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js +++ b/tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js @@ -159,7 +159,9 @@ declare const console: { log(msg: any): void; }; */ declare const _exports: {}; export = _exports; -export type Nominal = T & {}; +export type Nominal = T & { + [Symbol.species]: Name; +}; //// [/home/src/workspaces/lib/common/nominal.js] *new* "use strict"; @@ -170,7 +172,7 @@ export type Nominal = T & {}; module.exports = {}; //// [/home/src/workspaces/lib/common/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","../../solution/common/nominal.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a19075dfba5b2d593b761ed8d8cd526f-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};","signature":"81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n","impliedNodeFormat":1}],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"semanticDiagnosticsPerFile":[[2,[{"pos":51,"end":58,"code":2339,"category":1,"messageKey":"Property_0_does_not_exist_on_type_1_2339","messageArgs":["species","SymbolConstructor"]}]]],"latestChangedDtsFile":"./nominal.d.ts"} +{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","../../solution/common/nominal.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a19075dfba5b2d593b761ed8d8cd526f-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};","signature":"20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n","impliedNodeFormat":1}],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"semanticDiagnosticsPerFile":[[2,[{"pos":51,"end":58,"code":2339,"category":1,"messageKey":"Property_0_does_not_exist_on_type_1_2339","messageArgs":["species","SymbolConstructor"]}]]],"latestChangedDtsFile":"./nominal.d.ts"} //// [/home/src/workspaces/lib/common/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -202,11 +204,11 @@ module.exports = {}; { "fileName": "../../solution/common/nominal.js", "version": "a19075dfba5b2d593b761ed8d8cd526f-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};", - "signature": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", + "signature": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS", "original": { "version": "a19075dfba5b2d593b761ed8d8cd526f-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};", - "signature": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", + "signature": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": 1 } } @@ -239,7 +241,7 @@ module.exports = {}; ] ], "latestChangedDtsFile": "./nominal.d.ts", - "size": 1652 + "size": 1683 } //// [/home/src/workspaces/lib/sub-project-2/index.d.ts] *new* import { MyNominal } from '../sub-project/index'; @@ -265,7 +267,7 @@ export function getVar() { } //// [/home/src/workspaces/lib/sub-project-2/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[4],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../sub-project/index.d.ts","../../solution/sub-project-2/index.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n","225285a996cc5c4120877a377890d79e-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n/**\n * @typedef {Nominal} MyNominal\n */ \n",{"version":"db2a90e082fd17d65127bda69975a727-import { MyNominal } from '../sub-project/index';\n\nconst variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nexport function getVar() {\n return 'key';\n}","signature":"0620ca4a9fe7036c93bd1594ffccf8eb-import { MyNominal } from '../sub-project/index';\ndeclare const variable: {\n key: MyNominal;\n};\n/**\n * @return {keyof typeof variable}\n */\nexport declare function getVar(): keyof typeof variable;\nexport {};\n","impliedNodeFormat":1}],"fileIdsList":[[2],[3]],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"referencedMap":[[3,1],[4,2]],"semanticDiagnosticsPerFile":[[4,[{"pos":9,"end":18,"code":18042,"category":1,"messageKey":"_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation_18042","messageArgs":["MyNominal","import(\"../sub-project/index\").MyNominal"]}]]],"latestChangedDtsFile":"./index.d.ts"} +{"version":"FakeTSVersion","root":[4],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../sub-project/index.d.ts","../../solution/sub-project-2/index.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n","225285a996cc5c4120877a377890d79e-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n/**\n * @typedef {Nominal} MyNominal\n */ \n",{"version":"db2a90e082fd17d65127bda69975a727-import { MyNominal } from '../sub-project/index';\n\nconst variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nexport function getVar() {\n return 'key';\n}","signature":"0620ca4a9fe7036c93bd1594ffccf8eb-import { MyNominal } from '../sub-project/index';\ndeclare const variable: {\n key: MyNominal;\n};\n/**\n * @return {keyof typeof variable}\n */\nexport declare function getVar(): keyof typeof variable;\nexport {};\n","impliedNodeFormat":1}],"fileIdsList":[[2],[3]],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"referencedMap":[[3,1],[4,2]],"semanticDiagnosticsPerFile":[[4,[{"pos":9,"end":18,"code":18042,"category":1,"messageKey":"_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation_18042","messageArgs":["MyNominal","import(\"../sub-project/index\").MyNominal"]}]]],"latestChangedDtsFile":"./index.d.ts"} //// [/home/src/workspaces/lib/sub-project-2/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -298,8 +300,8 @@ export function getVar() { }, { "fileName": "../common/nominal.d.ts", - "version": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", - "signature": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", + "version": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", + "signature": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS" }, { @@ -364,7 +366,7 @@ export function getVar() { ] ], "latestChangedDtsFile": "./index.d.ts", - "size": 2414 + "size": 2445 } //// [/home/src/workspaces/lib/sub-project/index.d.ts] *new* import { Nominal } from '../common/nominal'; @@ -380,7 +382,7 @@ import { Nominal } from '../common/nominal'; */ //// [/home/src/workspaces/lib/sub-project/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../../solution/sub-project/index.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n",{"version":"00b7836eaf1e026f7764b7be6efcc8f5-import { Nominal } from '../common/nominal';\n\n/**\n * @typedef {Nominal} MyNominal\n */","signature":"225285a996cc5c4120877a377890d79e-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n/**\n * @typedef {Nominal} MyNominal\n */ \n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":9,"end":16,"code":18042,"category":1,"messageKey":"_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation_18042","messageArgs":["Nominal","import(\"../common/nominal\").Nominal"]}]]],"latestChangedDtsFile":"./index.d.ts"} +{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../../solution/sub-project/index.js"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n",{"version":"00b7836eaf1e026f7764b7be6efcc8f5-import { Nominal } from '../common/nominal';\n\n/**\n * @typedef {Nominal} MyNominal\n */","signature":"225285a996cc5c4120877a377890d79e-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n/**\n * @typedef {Nominal} MyNominal\n */ \n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../solution","skipLibCheck":true},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":9,"end":16,"code":18042,"category":1,"messageKey":"_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation_18042","messageArgs":["Nominal","import(\"../common/nominal\").Nominal"]}]]],"latestChangedDtsFile":"./index.d.ts"} //// [/home/src/workspaces/lib/sub-project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -412,8 +414,8 @@ import { Nominal } from '../common/nominal'; }, { "fileName": "../common/nominal.d.ts", - "version": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", - "signature": "81ac3a6e47fc4be420cd544e175d838d-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {};\n", + "version": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", + "signature": "20d096a1d9e8e1f99fd2356d60941715-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\ndeclare const _exports: {};\nexport = _exports;\nexport type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS" }, { @@ -466,7 +468,7 @@ import { Nominal } from '../common/nominal'; ] ], "latestChangedDtsFile": "./index.d.ts", - "size": 2004 + "size": 2035 } common/tsconfig.json:: diff --git a/tsc/testdata/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-resolve-correctly.js b/tsc/testdata/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-resolve-correctly.js index 69b0307205d71..eb7abc597983d 100644 --- a/tsc/testdata/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-resolve-correctly.js +++ b/tsc/testdata/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-resolve-correctly.js @@ -157,13 +157,15 @@ interface Symbol { } declare const console: { log(msg: any): void; }; //// [/home/src/workspaces/packages/lib/solution/common/nominal.d.ts] *new* -export declare type Nominal = T & {}; +export declare type Nominal = T & { + [Symbol.species]: Name; +}; //// [/home/src/workspaces/packages/lib/solution/common/nominal.js] *new* export {}; //// [/home/src/workspaces/packages/lib/solution/common/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","../../../solution/common/nominal.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6da5023bc256e774f9366f88c712bfc1-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};","signature":"6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n","impliedNodeFormat":1}],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"semanticDiagnosticsPerFile":[[2,[{"pos":72,"end":79,"code":2339,"category":1,"messageKey":"Property_0_does_not_exist_on_type_1_2339","messageArgs":["species","SymbolConstructor"]}]]],"latestChangedDtsFile":"./nominal.d.ts"} +{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","../../../solution/common/nominal.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6da5023bc256e774f9366f88c712bfc1-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};","signature":"5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n","impliedNodeFormat":1}],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"semanticDiagnosticsPerFile":[[2,[{"pos":72,"end":79,"code":2339,"category":1,"messageKey":"Property_0_does_not_exist_on_type_1_2339","messageArgs":["species","SymbolConstructor"]}]]],"latestChangedDtsFile":"./nominal.d.ts"} //// [/home/src/workspaces/packages/lib/solution/common/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -195,11 +197,11 @@ export {}; { "fileName": "../../../solution/common/nominal.ts", "version": "6da5023bc256e774f9366f88c712bfc1-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};", - "signature": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", + "signature": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS", "original": { "version": "6da5023bc256e774f9366f88c712bfc1-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};", - "signature": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", + "signature": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": 1 } } @@ -229,7 +231,7 @@ export {}; ] ], "latestChangedDtsFile": "./nominal.d.ts", - "size": 1481 + "size": 1512 } //// [/home/src/workspaces/packages/lib/solution/sub-project-2/index.d.ts] *new* import { MyNominal } from '../sub-project/index'; @@ -248,7 +250,7 @@ export function getVar() { } //// [/home/src/workspaces/packages/lib/solution/sub-project-2/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[4],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../sub-project/index.d.ts","../../../solution/sub-project-2/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n","ba931f9684d9e8eb38e02da33050dc55-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n",{"version":"8d7f0cd34ff9cb954b00662137820b98-import { MyNominal } from '../sub-project/index';\n\nconst variable = {\n key: 'value' as MyNominal,\n};\n\nexport function getVar(): keyof typeof variable {\n return 'key';\n}","signature":"d3fc4bf12d5f8dfcac4dd45791e378ef-import { MyNominal } from '../sub-project/index';\ndeclare const variable: {\n key: MyNominal;\n};\nexport declare function getVar(): keyof typeof variable;\nexport {};\n","impliedNodeFormat":1}],"fileIdsList":[[2],[3]],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"referencedMap":[[3,1],[4,2]],"latestChangedDtsFile":"./index.d.ts"} +{"version":"FakeTSVersion","root":[4],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../sub-project/index.d.ts","../../../solution/sub-project-2/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n","ba931f9684d9e8eb38e02da33050dc55-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n",{"version":"8d7f0cd34ff9cb954b00662137820b98-import { MyNominal } from '../sub-project/index';\n\nconst variable = {\n key: 'value' as MyNominal,\n};\n\nexport function getVar(): keyof typeof variable {\n return 'key';\n}","signature":"d3fc4bf12d5f8dfcac4dd45791e378ef-import { MyNominal } from '../sub-project/index';\ndeclare const variable: {\n key: MyNominal;\n};\nexport declare function getVar(): keyof typeof variable;\nexport {};\n","impliedNodeFormat":1}],"fileIdsList":[[2],[3]],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"referencedMap":[[3,1],[4,2]],"latestChangedDtsFile":"./index.d.ts"} //// [/home/src/workspaces/packages/lib/solution/sub-project-2/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -281,8 +283,8 @@ export function getVar() { }, { "fileName": "../common/nominal.d.ts", - "version": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", - "signature": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", + "version": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", + "signature": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS" }, { @@ -326,7 +328,7 @@ export function getVar() { ] }, "latestChangedDtsFile": "./index.d.ts", - "size": 1843 + "size": 1874 } //// [/home/src/workspaces/packages/lib/solution/sub-project/index.d.ts] *new* import { Nominal } from '../common/nominal'; @@ -336,7 +338,7 @@ export type MyNominal = Nominal; export {}; //// [/home/src/workspaces/packages/lib/solution/sub-project/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../../../solution/sub-project/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n",{"version":"17fb8188dac0968c390031165ecd45b6-import { Nominal } from '../common/nominal';\n\nexport type MyNominal = Nominal;","signature":"ba931f9684d9e8eb38e02da33050dc55-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"referencedMap":[[3,1]],"latestChangedDtsFile":"./index.d.ts"} +{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2026.full.d.ts","../common/nominal.d.ts","../../../solution/sub-project/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n",{"version":"17fb8188dac0968c390031165ecd45b6-import { Nominal } from '../common/nominal';\n\nexport type MyNominal = Nominal;","signature":"ba931f9684d9e8eb38e02da33050dc55-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"composite":true,"outDir":"../..","rootDir":"../../..","skipLibCheck":true},"referencedMap":[[3,1]],"latestChangedDtsFile":"./index.d.ts"} //// [/home/src/workspaces/packages/lib/solution/sub-project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -368,8 +370,8 @@ export {}; }, { "fileName": "../common/nominal.d.ts", - "version": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", - "signature": "6b86fa4ec711c70d7c514bb012b90db9-export declare type Nominal = T & {};\n", + "version": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", + "signature": "5e7f6e0ebb82be49de355c8db93969fe-export declare type Nominal = T & {\n [Symbol.species]: Name;\n};\n", "impliedNodeFormat": "CommonJS" }, { @@ -401,7 +403,7 @@ export {}; ] }, "latestChangedDtsFile": "./index.d.ts", - "size": 1513 + "size": 1544 } solution/common/tsconfig.json:: diff --git a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts index 6b4b8276e325f..aa8124bc95882 100644 --- a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts +++ b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedProperties.ts @@ -1,5 +1,5 @@ // @declaration: true -// @isolatedDeclarations: true +// @isolatedDeclarations: false, true // @strict: true // @target: esnext diff --git a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts index afaa95a8f7706..43c48953dcbfc 100644 --- a/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts +++ b/tsc/testdata/tests/cases/compiler/isolatedDeclarationsComputedPropertiesErrors.ts @@ -17,3 +17,8 @@ export const object = { export const invalidName = { [Math.random()]: 1, }; + +export const stringKey: string = "key"; +export const indexedObject = { + [stringKey]: Math.random(), +};