Skip to content

Commit e8a5bd2

Browse files
committed
Use checker for decl emit:optional parameter props
Optional parameter properties create a property with a type that unions with undefined when strictNullChecks is on. This needs to be reflected in the generated declaration.
1 parent d5ac244 commit e8a5bd2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,12 @@ namespace ts {
335335
write(": ");
336336

337337
// use the checker's type, not the declared type,
338-
// for non-optional initialized parameters that aren't a parameter property
338+
// for optional parameter properties
339+
// and also for non-optional initialized parameters that aren't a parameter property
340+
// these types may need to add `undefined`.
339341
const shouldUseResolverType = declaration.kind === SyntaxKind.Parameter &&
340-
resolver.isRequiredInitializedParameter(declaration as ParameterDeclaration);
342+
(resolver.isRequiredInitializedParameter(declaration as ParameterDeclaration) ||
343+
(getModifierFlags(declaration) & ModifierFlags.ParameterPropertyModifier && resolver.isOptionalParameter(declaration as ParameterDeclaration)));
341344
if (type && !shouldUseResolverType) {
342345
// Write the type
343346
emitType(type);

0 commit comments

Comments
 (0)