From e8a5bd20ae9c1c111b3893c47ae6553fdfd08579 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 13 Jun 2017 11:31:51 -0700 Subject: [PATCH] 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. --- src/compiler/declarationEmitter.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 007620ad510..8b4919e9da9 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -335,9 +335,12 @@ namespace ts { write(": "); // use the checker's type, not the declared type, - // for non-optional initialized parameters that aren't a parameter property + // for optional parameter properties + // and also for non-optional initialized parameters that aren't a parameter property + // these types may need to add `undefined`. const shouldUseResolverType = declaration.kind === SyntaxKind.Parameter && - resolver.isRequiredInitializedParameter(declaration as ParameterDeclaration); + (resolver.isRequiredInitializedParameter(declaration as ParameterDeclaration) || + (getModifierFlags(declaration) & ModifierFlags.ParameterPropertyModifier && resolver.isOptionalParameter(declaration as ParameterDeclaration))); if (type && !shouldUseResolverType) { // Write the type emitType(type);