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.
This commit is contained in:
Nathan Shively-Sanders
2017-06-13 11:31:51 -07:00
parent 23f618b6bc
commit 2a921d4b33

View File

@@ -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);