Add only 'undefined' to optional parameter types

This commit is contained in:
Anders Hejlsberg 2016-03-04 17:39:56 -08:00
parent 436e70ea8f
commit a0790fba7d

View file

@ -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(<ParameterDeclaration>declaration);
if (type) {
return declaration.questionToken ? getNullableType(type) : type;
return strictNullChecks && declaration.questionToken ? addNullableKind(type, TypeFlags.Undefined) : type;
}
}