Skip to content

Commit c72f5e2

Browse files
authored
Merge pull request microsoft#10543 from Microsoft/port10212
Port microsoft#10212
2 parents 0041d5c + 15ff0f7 commit c72f5e2

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/compiler/declarationEmitter.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,10 @@ namespace ts {
11321132
// it if it's not a well known symbol. In that case, the text of the name will be exactly
11331133
// what we want, namely the name expression enclosed in brackets.
11341134
writeTextOfNode(currentText, node.name);
1135-
// If optional property emit ?
1136-
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.Parameter) && hasQuestionToken(node)) {
1135+
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
1136+
// we don't want to emit property declaration with "?"
1137+
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
1138+
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) {
11371139
write("?");
11381140
}
11391141
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {

tests/baselines/reference/declFileConstructors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export declare class ConstructorWithPrivateParameterProperty {
247247
constructor(x: string);
248248
}
249249
export declare class ConstructorWithOptionalParameterProperty {
250-
x?: string;
250+
x: string;
251251
constructor(x?: string);
252252
}
253253
export declare class ConstructorWithParameterInitializer {
@@ -281,7 +281,7 @@ declare class GlobalConstructorWithPrivateParameterProperty {
281281
constructor(x: string);
282282
}
283283
declare class GlobalConstructorWithOptionalParameterProperty {
284-
x?: string;
284+
x: string;
285285
constructor(x?: string);
286286
}
287287
declare class GlobalConstructorWithParameterInitializer {

tests/baselines/reference/optionalMethods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ interface Foo {
126126
}
127127
declare function test1(x: Foo): void;
128128
declare class Bar {
129-
d?: number;
129+
d: number;
130130
e: number;
131131
a: number;
132132
b?: number;

0 commit comments

Comments
 (0)