Skip to content

Commit 6bf73a6

Browse files
committed
Declaration comments for call, constructo and index signatures in .d.ts
1 parent d970c89 commit 6bf73a6

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

src/compiler/emitter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,11 +2543,16 @@ module ts {
25432543
}
25442544

25452545
function emitConstructSignatureDeclaration(node: SignatureDeclaration) {
2546+
emitJsDocComments(node);
25462547
write("new ");
25472548
emitSignatureDeclaration(node);
25482549
}
25492550

25502551
function emitSignatureDeclaration(node: SignatureDeclaration) {
2552+
if (node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.IndexSignature) {
2553+
// Only index and call signatures are emitted directly, so emit their js doc comments, rest will do that in their own functions
2554+
emitJsDocComments(node);
2555+
}
25512556
emitTypeParameters(node.typeParameters);
25522557
if (node.kind === SyntaxKind.IndexSignature) {
25532558
write("[");

tests/baselines/reference/commentsInterface.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,14 @@ interface i2 {
117117
x: number;
118118
/** this is foo*/
119119
foo: (b: number) => string;
120+
/** this is indexer*/
120121
[i: string]: any;
122+
/**new method*/
121123
new (i: i1): any;
122124
nc_x: number;
123125
nc_foo: (b: number) => string;
124126
[i: number]: number;
127+
/** this is call signature*/
125128
(a: number, b: number): number;
126129
/** this is fnfoo*/
127130
fnfoo(b: number): string;

tests/baselines/reference/commentsOverloads.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ declare function f4(a: number): number;
274274
/** this is signature 4 - with string parameter*/
275275
declare function f4(b: string): number;
276276
interface i1 {
277+
/**this signature 1*/
277278
(a: number): number;
279+
/**this is signature 2*/
278280
(b: string): number;
279281
/** foo 1*/
280282
foo(a: number): number;
@@ -294,19 +296,25 @@ interface i1 {
294296
/** foo4 any */
295297
foo4(c: any): any;
296298
new (a: string): any;
299+
/** new 1*/
297300
new (b: number): any;
298301
}
299302
declare var i1_i: i1;
300303
interface i2 {
301304
new (a: string): any;
305+
/** new 2*/
302306
new (b: number): any;
303307
(a: number): number;
308+
/**this is signature 2*/
304309
(b: string): number;
305310
}
306311
declare var i2_i: i2;
307312
interface i3 {
313+
/** new 1*/
308314
new (a: string): any;
315+
/** new 2*/
309316
new (b: number): any;
317+
/**this is signature 1*/
310318
(a: number): number;
311319
(b: string): number;
312320
}

tests/baselines/reference/commentsemitComments.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ declare class c {
172172
declare var i: c;
173173
/** interface comments*/
174174
interface i1 {
175+
/** caller comments*/
175176
(a: number): number;
177+
/** new comments*/
176178
new (b: string): any;
179+
/**indexer property*/
177180
[a: number]: string;
178181
/** function property;*/
179182
myFoo(a: number): string;

tests/baselines/reference/declFileCallSignatures.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ interface IGlobalCallSignatureWithOwnTypeParametes {
7171

7272
//// [declFileCallSignatures_0.d.ts]
7373
export interface ICallSignature {
74+
/** This comment should appear for foo*/
7475
(): string;
7576
}
7677
export interface ICallSignatureWithParameters {
78+
/** This is comment for function signature*/
7779
(a: string, b: number): void;
7880
}
7981
export interface ICallSignatureWithRestParameters {
@@ -84,16 +86,19 @@ export interface ICallSignatureWithOverloads {
8486
(a: number): number;
8587
}
8688
export interface ICallSignatureWithTypeParameters<T> {
89+
/** This comment should appear for foo*/
8790
(a: T): string;
8891
}
8992
export interface ICallSignatureWithOwnTypeParametes {
9093
<T extends ICallSignature>(a: T): string;
9194
}
9295
//// [declFileCallSignatures_1.d.ts]
9396
interface IGlobalCallSignature {
97+
/** This comment should appear for foo*/
9498
(): string;
9599
}
96100
interface IGlobalCallSignatureWithParameters {
101+
/** This is comment for function signature*/
97102
(a: string, b: number): void;
98103
}
99104
interface IGlobalCallSignatureWithRestParameters {
@@ -104,6 +109,7 @@ interface IGlobalCallSignatureWithOverloads {
104109
(a: number): number;
105110
}
106111
interface IGlobalCallSignatureWithTypeParameters<T> {
112+
/** This comment should appear for foo*/
107113
(a: T): string;
108114
}
109115
interface IGlobalCallSignatureWithOwnTypeParametes {

tests/baselines/reference/declFileConstructSignatures.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ interface IGlobalConstructSignatureWithOwnTypeParametes {
7171

7272
//// [declFileConstructSignatures_0.d.ts]
7373
export interface IConstructSignature {
74+
/** This comment should appear for foo*/
7475
new (): string;
7576
}
7677
export interface IConstructSignatureWithParameters {
78+
/** This is comment for function signature*/
7779
new (a: string, b: number): any;
7880
}
7981
export interface IConstructSignatureWithRestParameters {
@@ -84,16 +86,19 @@ export interface IConstructSignatureWithOverloads {
8486
new (a: number): number;
8587
}
8688
export interface IConstructSignatureWithTypeParameters<T> {
89+
/** This comment should appear for foo*/
8790
new (a: T): T;
8891
}
8992
export interface IConstructSignatureWithOwnTypeParametes {
9093
new <T extends IConstructSignature>(a: T): T;
9194
}
9295
//// [declFileConstructSignatures_1.d.ts]
9396
interface IGlobalConstructSignature {
97+
/** This comment should appear for foo*/
9498
new (): string;
9599
}
96100
interface IGlobalConstructSignatureWithParameters {
101+
/** This is comment for function signature*/
97102
new (a: string, b: number): any;
98103
}
99104
interface IGlobalConstructSignatureWithRestParameters {
@@ -104,6 +109,7 @@ interface IGlobalConstructSignatureWithOverloads {
104109
new (a: number): number;
105110
}
106111
interface IGlobalConstructSignatureWithTypeParameters<T> {
112+
/** This comment should appear for foo*/
107113
new (a: T): T;
108114
}
109115
interface IGlobalConstructSignatureWithOwnTypeParametes {

0 commit comments

Comments
 (0)