mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user