Add test for invalid property access in unions

This commit is contained in:
Omer Sheikh 2016-08-29 01:07:10 +05:00
parent 59d027b49b
commit 4eaee73564
3 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,60 @@
tests/cases/compiler/unionPropertyExistance.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'.
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'.
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'.
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'.
Property 'inNone' does not exist on type 'A'.
==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ====
interface A {
inAll: string;
notInB: string;
notInC: string;
}
interface B {
inAll: boolean;
onlyInB: number;
notInC: string;
}
interface C {
inAll: number;
notInB: string;
}
type AB = A | B;
type ABC = C | AB;
var ab: AB;
var abc: ABC;
ab.onlyInB;
~~~~~~~
!!! error TS2339: Property 'onlyInB' does not exist on type 'AB'.
!!! error TS2339: Property 'onlyInB' does not exist on type 'A'.
ab.notInC; // Ok
abc.notInC;
~~~~~~
!!! error TS2339: Property 'notInC' does not exist on type 'ABC'.
!!! error TS2339: Property 'notInC' does not exist on type 'C'.
ab.notInB;
~~~~~~
!!! error TS2339: Property 'notInB' does not exist on type 'AB'.
!!! error TS2339: Property 'notInB' does not exist on type 'B'.
abc.notInB;
~~~~~~
!!! error TS2339: Property 'notInB' does not exist on type 'ABC'.
!!! error TS2339: Property 'notInB' does not exist on type 'B'.
abc.inAll; // Ok
abc.inNone;
~~~~~~
!!! error TS2339: Property 'inNone' does not exist on type 'ABC'.
!!! error TS2339: Property 'inNone' does not exist on type 'A'.

View File

@ -0,0 +1,44 @@
//// [unionPropertyExistance.ts]
interface A {
inAll: string;
notInB: string;
notInC: string;
}
interface B {
inAll: boolean;
onlyInB: number;
notInC: string;
}
interface C {
inAll: number;
notInB: string;
}
type AB = A | B;
type ABC = C | AB;
var ab: AB;
var abc: ABC;
ab.onlyInB;
ab.notInC; // Ok
abc.notInC;
ab.notInB;
abc.notInB;
abc.inAll; // Ok
abc.inNone;
//// [unionPropertyExistance.js]
var ab;
var abc;
ab.onlyInB;
ab.notInC; // Ok
abc.notInC;
ab.notInB;
abc.notInB;
abc.inAll; // Ok
abc.inNone;

View File

@ -0,0 +1,32 @@
interface A {
inAll: string;
notInB: string;
notInC: string;
}
interface B {
inAll: boolean;
onlyInB: number;
notInC: string;
}
interface C {
inAll: number;
notInB: string;
}
type AB = A | B;
type ABC = C | AB;
var ab: AB;
var abc: ABC;
ab.onlyInB;
ab.notInC; // Ok
abc.notInC;
ab.notInB;
abc.notInB;
abc.inAll; // Ok
abc.inNone;