From 41401c7caeb73d45c08ea8fa2f18d90e6a401458 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 15 Feb 2016 17:02:43 -0800 Subject: [PATCH] Make types of optional parameters and properties nullable --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1464d719478..c7e74d86f90 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2677,7 +2677,8 @@ namespace ts { // Use type from type annotation if one is present if (declaration.type) { - return getTypeFromTypeNode(declaration.type); + const type = getTypeFromTypeNode(declaration.type); + return declaration.questionToken ? getNullableType(type) : type; } if (declaration.kind === SyntaxKind.Parameter) { @@ -2692,7 +2693,7 @@ namespace ts { // Use contextual parameter type if one is available const type = getContextuallyTypedParameterType(declaration); if (type) { - return type; + return declaration.questionToken ? getNullableType(type) : type; } }