From a0790fba7df3ee2109282a56d2635bfd3a09c35c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 4 Mar 2016 17:39:56 -0800 Subject: [PATCH] Add only 'undefined' to optional parameter types --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } }