Skip to content

Commit fe570ba

Browse files
committed
Do not elaborate on primitive type unions
1 parent 4eaee73 commit fe570ba

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10773,7 +10773,7 @@ namespace ts {
1077310773
const prop = getPropertyOfType(apparentType, right.text);
1077410774
if (!prop) {
1077510775
if (right.text && !checkAndReportErrorForExtendingInterface(node)) {
10776-
reportNonexistantProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
10776+
reportNonexistentProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
1077710777
}
1077810778
return unknownType;
1077910779
}
@@ -10811,9 +10811,9 @@ namespace ts {
1081110811
}
1081210812
return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined);
1081310813

10814-
function reportNonexistantProperty(propNode: Identifier, containingType: Type) {
10814+
function reportNonexistentProperty(propNode: Identifier, containingType: Type) {
1081510815
let errorInfo: DiagnosticMessageChain;
10816-
if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Enum)) {
10816+
if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) {
1081710817
for (const subtype of (containingType as UnionType).types) {
1081810818
if (!getPropertyOfType(subtype, propNode.text)) {
1081910819
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype));
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
tests/cases/compiler/propertyAccess3.ts(2,5): error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
2-
Property 'toBAZ' does not exist on type 'true'.
32

43

54
==== tests/cases/compiler/propertyAccess3.ts (1 errors) ====
65
var foo: boolean;
76
foo.toBAZ();
87
~~~~~
9-
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.
10-
!!! error TS2339: Property 'toBAZ' does not exist on type 'true'.
8+
!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'.

tests/baselines/reference/typeGuardsWithAny.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(11,7): error TS2339: Property 'p' does not exist on type 'string'.
22
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(18,7): error TS2339: Property 'p' does not exist on type 'number'.
33
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error TS2339: Property 'p' does not exist on type 'boolean'.
4-
Property 'p' does not exist on type 'true'.
54

65

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

tests/baselines/reference/unionPropertyExistance.errors.txt renamed to tests/baselines/reference/unionPropertyExistence.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
tests/cases/compiler/unionPropertyExistance.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
1+
tests/cases/compiler/unionPropertyExistence.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'.
22
Property 'onlyInB' does not exist on type 'A'.
3-
tests/cases/compiler/unionPropertyExistance.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
3+
tests/cases/compiler/unionPropertyExistence.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'.
44
Property 'notInC' does not exist on type 'C'.
5-
tests/cases/compiler/unionPropertyExistance.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
5+
tests/cases/compiler/unionPropertyExistence.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'.
66
Property 'notInB' does not exist on type 'B'.
7-
tests/cases/compiler/unionPropertyExistance.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
7+
tests/cases/compiler/unionPropertyExistence.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'.
88
Property 'notInB' does not exist on type 'B'.
9-
tests/cases/compiler/unionPropertyExistance.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
9+
tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'.
1010
Property 'inNone' does not exist on type 'A'.
1111

1212

13-
==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ====
13+
==== tests/cases/compiler/unionPropertyExistence.ts (5 errors) ====
1414
interface A {
1515
inAll: string;
1616
notInB: string;

tests/baselines/reference/unionPropertyExistance.js renamed to tests/baselines/reference/unionPropertyExistence.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [unionPropertyExistance.ts]
1+
//// [unionPropertyExistence.ts]
22
interface A {
33
inAll: string;
44
notInB: string;
@@ -32,7 +32,7 @@ abc.notInB;
3232
abc.inAll; // Ok
3333
abc.inNone;
3434

35-
//// [unionPropertyExistance.js]
35+
//// [unionPropertyExistence.js]
3636
var ab;
3737
var abc;
3838
ab.onlyInB;

0 commit comments

Comments
 (0)