File: unionTypeMembers.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (82 lines) | stat: -rw-r--r-- 4,581 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
tests/cases/conformance/types/union/unionTypeMembers.ts(44,38): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'.
  Type 'string' is not assignable to type 'never'.
tests/cases/conformance/types/union/unionTypeMembers.ts(51,3): error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I1<number> | I2<number>'.
  Property 'propertyOnlyInI1' does not exist on type 'I2<number>'.
tests/cases/conformance/types/union/unionTypeMembers.ts(52,3): error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1<number> | I2<number>'.
  Property 'propertyOnlyInI2' does not exist on type 'I1<number>'.
tests/cases/conformance/types/union/unionTypeMembers.ts(53,3): error TS2339: Property 'methodOnlyInI1' does not exist on type 'I1<number> | I2<number>'.
  Property 'methodOnlyInI1' does not exist on type 'I2<number>'.
tests/cases/conformance/types/union/unionTypeMembers.ts(54,3): error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1<number> | I2<number>'.
  Property 'methodOnlyInI2' does not exist on type 'I1<number>'.


==== tests/cases/conformance/types/union/unionTypeMembers.ts (5 errors) ====
    interface I1<T> {
        commonMethodType(a: string): string;
        commonPropertyType: string;
    
        commonMethodDifferentParameterType(a: string): string;
        commonMethodDifferentReturnType(a: string): string;
        commonPropertyDifferenType: string;
    
        commonMethodWithTypeParameter(a: T): T;
        commonMethodWithOwnTypeParameter<U>(a: U): U;
    
        methodOnlyInI1(a: string): string;
        propertyOnlyInI1: string;
    }
    
    interface I2<T> {
        commonMethodType(a: string): string;
        commonPropertyType: string;
    
        commonMethodDifferentParameterType(a: number): number;
        commonMethodDifferentReturnType(a: string): number;
        commonPropertyDifferenType: number;
    
        commonMethodWithTypeParameter(a: T): T;
        commonMethodWithOwnTypeParameter<U>(a: U): U;
    
        methodOnlyInI2(a: string): string;
        propertyOnlyInI2: string;
    }
    
    // a union type U has those members that are present in every one of its constituent types, 
    // with types that are unions of the respective members in the constituent types
    var x : I1<number> | I2<number>;
    var str: string;
    var num: number;
    var strOrNum: string | number;
    
    // If each type in U has a property P, U has a property P of a union type of the types of P from each type in U.
    str = x.commonPropertyType; // string
    str = x.commonMethodType(str); // (a: string) => string so result should be string
    strOrNum = x.commonPropertyDifferenType;
    strOrNum = x.commonMethodDifferentReturnType(str); // string | union
    x.commonMethodDifferentParameterType; // No error - property exists
    x.commonMethodDifferentParameterType(strOrNum); // error - no call signatures because the type of this property is ((a: string) => string) | (a: number) => number
                                         ~~~~~~~~
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'.
!!! error TS2345:   Type 'string' is not assignable to type 'never'.
                                                    // and the call signatures arent identical
    num = x.commonMethodWithTypeParameter(num);
    num = x.commonMethodWithOwnTypeParameter(num);
    str = x.commonMethodWithOwnTypeParameter(str);
    strOrNum = x.commonMethodWithOwnTypeParameter(strOrNum);
    
    x.propertyOnlyInI1; // error
      ~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I1<number> | I2<number>'.
!!! error TS2339:   Property 'propertyOnlyInI1' does not exist on type 'I2<number>'.
    x.propertyOnlyInI2; // error
      ~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1<number> | I2<number>'.
!!! error TS2339:   Property 'propertyOnlyInI2' does not exist on type 'I1<number>'.
    x.methodOnlyInI1("hello"); // error
      ~~~~~~~~~~~~~~
!!! error TS2339: Property 'methodOnlyInI1' does not exist on type 'I1<number> | I2<number>'.
!!! error TS2339:   Property 'methodOnlyInI1' does not exist on type 'I2<number>'.
    x.methodOnlyInI2(10); // error
      ~~~~~~~~~~~~~~
!!! error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1<number> | I2<number>'.
!!! error TS2339:   Property 'methodOnlyInI2' does not exist on type 'I1<number>'.