From b17e75b52b99b4fa793a4f46eadde63d87d6fe2c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 24 Oct 2017 13:27:55 -0700 Subject: [PATCH] Missing properties in fresh object literals are known to be undefined --- src/compiler/checker.ts | 9 +++++++++ src/compiler/commandLineParser.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aaaa0ed50b8..4e1f14974fe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9604,6 +9604,15 @@ namespace ts { } return Ternary.False; } + if (relation === subtypeRelation && target.flags & TypeFlags.FreshLiteral) { + const excessProperty = getUnmatchedProperty(target, source, /*requireOptionalProperties*/ true); + if (excessProperty) { + if (reportErrors) { + reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(excessProperty), typeToString(target)); + } + return Ternary.False; + } + } let result = Ternary.True; const properties = getPropertiesOfObjectType(target); for (const targetProp of properties) { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index f050c4a5d16..27b2d9f5087 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1273,7 +1273,7 @@ namespace ts { return result; } - function getDefaultValueForOption(option: CommandLineOption) { + function getDefaultValueForOption(option: CommandLineOption): {} { switch (option.type) { case "number": return 1;