File: intersectionWithConflictingPrivates.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 (70 lines) | stat: -rw-r--r-- 2,445 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
tests/cases/compiler/intersectionWithConflictingPrivates.ts(5,4): error TS2339: Property 'y' does not exist on type 'never'.
  The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
tests/cases/compiler/intersectionWithConflictingPrivates.ts(6,1): error TS2322: Type '{}' is not assignable to type 'never'.
  The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.


==== tests/cases/compiler/intersectionWithConflictingPrivates.ts (2 errors) ====
    class A { private x: unknown; y?: string; }
    class B { private x: unknown; y?: string; }
    
    declare let ab: A & B;
    ab.y = 'hello';
       ~
!!! error TS2339: Property 'y' does not exist on type 'never'.
!!! error TS2339:   The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
    ab = {};
    ~~
!!! error TS2322: Type '{}' is not assignable to type 'never'.
!!! error TS2322:   The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
    
    function f1(node: A | B) {
      if (node instanceof A || node instanceof A) {
        node;  // A
      }
      else {
        node;  // B
      }
      node;  // A | B
    }
    
    // Repro from #37659
    
    abstract class ViewNode { }
    abstract class ViewRefNode extends ViewNode { }
    abstract class ViewRefFileNode extends ViewRefNode { }
    
    class CommitFileNode extends ViewRefFileNode {
      private _id: any;
    }
    
    class ResultsFileNode extends ViewRefFileNode {
      private _id: any;
    }
    
    class StashFileNode extends CommitFileNode { 
      private _id2: any;
    }
    
    class StatusFileNode extends ViewNode {
      private _id: any;
    }
    
    class Foo {
      private async foo(node: CommitFileNode | ResultsFileNode | StashFileNode) {
    		if (
    			!(node instanceof CommitFileNode) &&
    			!(node instanceof StashFileNode) &&
    			!(node instanceof ResultsFileNode)
    		) {
    			return;
    		}
    
    		await this.bar(node);
    	}
    
      private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) {
        return Promise.resolve(undefined);
      }
    }