From 9990f5264df5b3ecacd1dcebe048fbeedadc006f Mon Sep 17 00:00:00 2001 From: shakilurrehman21 Date: Sat, 21 Nov 2026 13:05:37 +0530 Subject: [PATCH 1/2] Fix panic in declaration emit with stripInternal on parenthesized and wrapped types Fixes #65623 --- .../transformers/declarations/transform.go | 30 +++++++++++++ ...ationEmitStripInternalParenthesizedType.js | 44 +++++++++++++++++++ ...EmitStripInternalParenthesizedType.symbols | 33 ++++++++++++++ ...onEmitStripInternalParenthesizedType.types | 28 ++++++++++++ ...ationEmitStripInternalParenthesizedType.ts | 19 ++++++++ 5 files changed, 154 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types create mode 100644 tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 8b5b449ec87f5..86b3d506a6bc8 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -672,6 +672,12 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast. tx.EmitContext().AddEmitFlags(result, printer.EFSingleLine) } } + case ast.KindParenthesizedType: + result = tx.transformParenthesizedType(input.AsParenthesizedTypeNode()) + case ast.KindTypeOperator: + result = tx.transformTypeOperator(input.AsTypeOperatorNode()) + case ast.KindArrayType: + result = tx.transformArrayType(input.AsArrayTypeNode()) case ast.KindJSDocTypeExpression: result = tx.transformJSDocTypeExpression(input.AsJSDocTypeExpression()) case ast.KindJSDocTypeLiteral: @@ -807,6 +813,30 @@ func (tx *DeclarationTransformer) transformConditionalTypeNode(input *ast.Condit ) } +func (tx *DeclarationTransformer) transformParenthesizedType(input *ast.ParenthesizedTypeNode) *ast.Node { + t := tx.Visitor().Visit(input.Type) + if t == nil { + return nil + } + return tx.Factory().UpdateParenthesizedTypeNode(input, t) +} + +func (tx *DeclarationTransformer) transformTypeOperator(input *ast.TypeOperatorNode) *ast.Node { + t := tx.Visitor().Visit(input.Type) + if t == nil { + return nil + } + return tx.Factory().UpdateTypeOperatorNode(input, input.Operator, t) +} + +func (tx *DeclarationTransformer) transformArrayType(input *ast.ArrayTypeNode) *ast.Node { + elem := tx.Visitor().Visit(input.ElementType) + if elem == nil { + return nil + } + return tx.Factory().UpdateArrayTypeNode(input, elem) +} + func (tx *DeclarationTransformer) transformTypeReference(input *ast.TypeReferenceNode) *ast.Node { tx.checkEntityNameVisibility(input.TypeName, tx.enclosingDeclaration) return tx.Visitor().VisitEachChild(input.AsNode()) diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js new file mode 100644 index 0000000000000..ac8adfad5935c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts] //// + +//// [declarationEmitStripInternalParenthesizedType.ts] +interface Foo {} + +export type T = ( + /** @internal */ + Foo +); + +export const x: ( + /** @internal */ + Foo +) = {} as any; + +export type T2 = readonly ( + /** @internal */ + Foo +)[]; + + +//// [declarationEmitStripInternalParenthesizedType.js] +export const x = {}; + + +//// [declarationEmitStripInternalParenthesizedType.d.ts] +export type T = any; +export declare const x; +export type T2 = any; + + +//// [DtsFileErrors] + + +declarationEmitStripInternalParenthesizedType.d.ts(2,22): error TS7005: Variable 'x' implicitly has an 'any' type. + + +==== declarationEmitStripInternalParenthesizedType.d.ts (1 errors) ==== + export type T = any; + export declare const x; + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + export type T2 = any; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols new file mode 100644 index 0000000000000..4beef9aae1685 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts] //// + +=== declarationEmitStripInternalParenthesizedType.ts === +interface Foo {} +>Foo : Symbol(Foo, Decl(declarationEmitStripInternalParenthesizedType.ts, 0, 0)) + +export type T = ( +>T : Symbol(T, Decl(declarationEmitStripInternalParenthesizedType.ts, 0, 16)) + + /** @internal */ + Foo +>Foo : Symbol(Foo, Decl(declarationEmitStripInternalParenthesizedType.ts, 0, 0)) + +); + +export const x: ( +>x : Symbol(x, Decl(declarationEmitStripInternalParenthesizedType.ts, 7, 12)) + + /** @internal */ + Foo +>Foo : Symbol(Foo, Decl(declarationEmitStripInternalParenthesizedType.ts, 0, 0)) + +) = {} as any; + +export type T2 = readonly ( +>T2 : Symbol(T2, Decl(declarationEmitStripInternalParenthesizedType.ts, 10, 14)) + + /** @internal */ + Foo +>Foo : Symbol(Foo, Decl(declarationEmitStripInternalParenthesizedType.ts, 0, 0)) + +)[]; + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types new file mode 100644 index 0000000000000..6b545b27c301b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts] //// + +=== declarationEmitStripInternalParenthesizedType.ts === +interface Foo {} + +export type T = ( +>T : Foo + + /** @internal */ + Foo +); + +export const x: ( +>x : Foo + + /** @internal */ + Foo +) = {} as any; +>{} as any : any +>{} : {} + +export type T2 = readonly ( +>T2 : T2 + + /** @internal */ + Foo +)[]; + diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts b/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts new file mode 100644 index 0000000000000..e2a3148ebdd93 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts @@ -0,0 +1,19 @@ +// @declaration: true +// @stripInternal: true + +interface Foo {} + +export type T = ( + /** @internal */ + Foo +); + +export const x: ( + /** @internal */ + Foo +) = {} as any; + +export type T2 = readonly ( + /** @internal */ + Foo +)[]; From deb9bcef321ad4f8b58102ae0f4a454e5d5b1c47 Mon Sep 17 00:00:00 2001 From: shakilurrehman21 Date: Sat, 21 Nov 2026 16:03:04 +0530 Subject: [PATCH 2/2] Handle indexed access types when operands are stripped --- .../transformers/declarations/transform.go | 11 ++++++++ ...ationEmitStripInternalParenthesizedType.js | 26 +++++++++++++++++++ ...EmitStripInternalParenthesizedType.symbols | 24 +++++++++++++++++ ...onEmitStripInternalParenthesizedType.types | 19 ++++++++++++++ ...ationEmitStripInternalParenthesizedType.ts | 14 ++++++++++ 5 files changed, 94 insertions(+) diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 86b3d506a6bc8..9b25fbe2a9501 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -678,6 +678,8 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast. result = tx.transformTypeOperator(input.AsTypeOperatorNode()) case ast.KindArrayType: result = tx.transformArrayType(input.AsArrayTypeNode()) + case ast.KindIndexedAccessType: + result = tx.transformIndexedAccessType(input.AsIndexedAccessTypeNode()) case ast.KindJSDocTypeExpression: result = tx.transformJSDocTypeExpression(input.AsJSDocTypeExpression()) case ast.KindJSDocTypeLiteral: @@ -837,6 +839,15 @@ func (tx *DeclarationTransformer) transformArrayType(input *ast.ArrayTypeNode) * return tx.Factory().UpdateArrayTypeNode(input, elem) } +func (tx *DeclarationTransformer) transformIndexedAccessType(input *ast.IndexedAccessTypeNode) *ast.Node { + objectType := tx.Visitor().Visit(input.ObjectType) + indexType := tx.Visitor().Visit(input.IndexType) + if objectType == nil || indexType == nil { + return nil + } + return tx.Factory().UpdateIndexedAccessTypeNode(input, objectType, indexType) +} + func (tx *DeclarationTransformer) transformTypeReference(input *ast.TypeReferenceNode) *ast.Node { tx.checkEntityNameVisibility(input.TypeName, tx.enclosingDeclaration) return tx.Visitor().VisitEachChild(input.AsNode()) diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js index ac8adfad5935c..921d7383e472f 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.js @@ -17,6 +17,20 @@ export type T2 = readonly ( /** @internal */ Foo )[]; + +interface Bar { + x: string; +} + +export type T3 = ( + /** @internal */ + Bar +)["x"]; + +export type T4 = Bar[( + /** @internal */ + "x" +)]; //// [declarationEmitStripInternalParenthesizedType.js] @@ -27,6 +41,12 @@ export const x = {}; export type T = any; export declare const x; export type T2 = any; +interface Bar { + x: string; +} +export type T3 = any; +export type T4 = any; +export {}; //// [DtsFileErrors] @@ -41,4 +61,10 @@ declarationEmitStripInternalParenthesizedType.d.ts(2,22): error TS7005: Variable ~ !!! error TS7005: Variable 'x' implicitly has an 'any' type. export type T2 = any; + interface Bar { + x: string; + } + export type T3 = any; + export type T4 = any; + export {}; \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols index 4beef9aae1685..69dfc5aa3da36 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.symbols @@ -31,3 +31,27 @@ export type T2 = readonly ( )[]; +interface Bar { +>Bar : Symbol(Bar, Decl(declarationEmitStripInternalParenthesizedType.ts, 15, 4)) + + x: string; +>x : Symbol(Bar.x, Decl(declarationEmitStripInternalParenthesizedType.ts, 17, 15)) +} + +export type T3 = ( +>T3 : Symbol(T3, Decl(declarationEmitStripInternalParenthesizedType.ts, 19, 1)) + + /** @internal */ + Bar +>Bar : Symbol(Bar, Decl(declarationEmitStripInternalParenthesizedType.ts, 15, 4)) + +)["x"]; + +export type T4 = Bar[( +>T4 : Symbol(T4, Decl(declarationEmitStripInternalParenthesizedType.ts, 24, 7)) +>Bar : Symbol(Bar, Decl(declarationEmitStripInternalParenthesizedType.ts, 15, 4)) + + /** @internal */ + "x" +)]; + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types index 6b545b27c301b..c09fa2f324a0f 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitStripInternalParenthesizedType.types @@ -26,3 +26,22 @@ export type T2 = readonly ( Foo )[]; +interface Bar { + x: string; +>x : string +} + +export type T3 = ( +>T3 : string + + /** @internal */ + Bar +)["x"]; + +export type T4 = Bar[( +>T4 : string + + /** @internal */ + "x" +)]; + diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts b/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts index e2a3148ebdd93..e915140811ff0 100644 --- a/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts +++ b/tsc/testdata/tests/cases/compiler/declarationEmitStripInternalParenthesizedType.ts @@ -17,3 +17,17 @@ export type T2 = readonly ( /** @internal */ Foo )[]; + +interface Bar { + x: string; +} + +export type T3 = ( + /** @internal */ + Bar +)["x"]; + +export type T4 = Bar[( + /** @internal */ + "x" +)];