Do not elaborate on primitive type unions

This commit is contained in:
Omer Sheikh 2016-08-29 09:34:46 +05:00
parent 4eaee73564
commit fe570ba764
6 changed files with 12 additions and 16 deletions

View File

@ -10773,7 +10773,7 @@ namespace ts {
const prop = getPropertyOfType(apparentType, right.text);
if (!prop) {
if (right.text && !checkAndReportErrorForExtendingInterface(node)) {
reportNonexistantProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
reportNonexistentProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
}
return unknownType;
}
@ -10811,9 +10811,9 @@ namespace ts {
}
return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined);
function reportNonexistantProperty(propNode: Identifier, containingType: Type) {
function reportNonexistentProperty(propNode: Identifier, containingType: Type) {
let errorInfo: DiagnosticMessageChain;
if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Enum)) {
if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) {
for (const subtype of (containingType as UnionType).types) {
if (!getPropertyOfType(subtype, propNode.text)) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype));

View File

@ -1,10 +1,8 @@
tests/cases/compiler/propertyAccess3.ts(2,5): error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
Property 'toBAZ' does not exist on type 'true'.
==== tests/cases/compiler/propertyAccess3.ts (1 errors) ====
var foo: boolean;
foo.toBAZ();
~~~~~
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
!!! error TS2339: Property 'toBAZ' does not exist on type 'true'.
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.

View File

@ -1,7 +1,6 @@
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(11,7): error TS2339: Property 'p' does not exist on type 'string'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(18,7): error TS2339: Property 'p' does not exist on type 'number'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error TS2339: Property 'p' does not exist on type 'boolean'.
Property 'p' does not exist on type 'true'.
==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts (3 errors) ====
@ -36,7 +35,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error
x.p; // Error, type any narrowed by primitive type check
~
!!! error TS2339: Property 'p' does not exist on type 'boolean'.
!!! error TS2339: Property 'p' does not exist on type 'true'.
}
else {
x.p; // No error, type unaffected in this branch

View File

@ -1,16 +1,16 @@
tests/cases/compiler/unionPropertyExistance.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
tests/cases/compiler/unionPropertyExistence.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
Property 'onlyInB' does not exist on type 'A'.
tests/cases/compiler/unionPropertyExistance.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
tests/cases/compiler/unionPropertyExistence.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
Property 'notInC' does not exist on type 'C'.
tests/cases/compiler/unionPropertyExistance.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
tests/cases/compiler/unionPropertyExistence.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
Property 'notInB' does not exist on type 'B'.
tests/cases/compiler/unionPropertyExistance.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
tests/cases/compiler/unionPropertyExistence.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
Property 'notInB' does not exist on type 'B'.
tests/cases/compiler/unionPropertyExistance.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
Property 'inNone' does not exist on type 'A'.
==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ====
==== tests/cases/compiler/unionPropertyExistence.ts (5 errors) ====
interface A {
inAll: string;
notInB: string;

View File

@ -1,4 +1,4 @@
//// [unionPropertyExistance.ts]
//// [unionPropertyExistence.ts]
interface A {
inAll: string;
notInB: string;
@ -32,7 +32,7 @@ abc.notInB;
abc.inAll; // Ok
abc.inNone;
//// [unionPropertyExistance.js]
//// [unionPropertyExistence.js]
var ab;
var abc;
ab.onlyInB;