diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 15a57ed8931..9384145164e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2698,7 +2698,7 @@ namespace ts { // Use type from type annotation if one is present if (declaration.type) { const type = getTypeFromTypeNode(declaration.type); - return declaration.questionToken ? getNullableType(type) : type; + return strictNullChecks && declaration.questionToken ? addNullableKind(type, TypeFlags.Undefined) : type; } if (declaration.kind === SyntaxKind.Parameter) { @@ -2713,7 +2713,7 @@ namespace ts { // Use contextual parameter type if one is available const type = getContextuallyTypedParameterType(declaration); if (type) { - return declaration.questionToken ? getNullableType(type) : type; + return strictNullChecks && declaration.questionToken ? addNullableKind(type, TypeFlags.Undefined) : type; } }