Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tsc/internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ 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.KindIndexedAccessType:
result = tx.transformIndexedAccessType(input.AsIndexedAccessTypeNode())
case ast.KindJSDocTypeExpression:
result = tx.transformJSDocTypeExpression(input.AsJSDocTypeExpression())
case ast.KindJSDocTypeLiteral:
Expand Down Expand Up @@ -807,6 +815,39 @@ 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
Comment thread
ShakilUrRehman21 marked this conversation as resolved.
Resolved
}
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) 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())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//// [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
)[];

interface Bar {
x: string;
}

export type T3 = (
/** @internal */
Bar
)["x"];

export type T4 = Bar[(
/** @internal */
"x"
)];


//// [declarationEmitStripInternalParenthesizedType.js]
export const x = {};


//// [declarationEmitStripInternalParenthesizedType.d.ts]
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]


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;
interface Bar {
x: string;
}
export type T3 = any;
export type T4 = any;
export {};

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//// [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))

)[];

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"
)];

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [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
)[];

interface Bar {
x: string;
>x : string
}

export type T3 = (
>T3 : string

/** @internal */
Bar
)["x"];

export type T4 = Bar[(
>T4 : string

/** @internal */
"x"
)];

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @declaration: true
// @stripInternal: true

interface Foo {}

export type T = (
/** @internal */
Foo
);

export const x: (
/** @internal */
Foo
) = {} as any;

export type T2 = readonly (
/** @internal */
Foo
)[];

interface Bar {
x: string;
}

export type T3 = (
/** @internal */
Bar
)["x"];

export type T4 = Bar[(
/** @internal */
"x"
)];