File tree Expand file tree Collapse file tree 3 files changed +171
-0
lines changed
cases/conformance/expressions/contextualTyping Expand file tree Collapse file tree 3 files changed +171
-0
lines changed Original file line number Diff line number Diff line change
1
+ //// [superCallParameterContextualTyping3.ts]
2
+ interface ContextualType < T > {
3
+ method ( parameter : T ) : void ;
4
+ }
5
+
6
+ class CBase < T > {
7
+ constructor ( param : ContextualType < T > ) {
8
+ }
9
+
10
+ foo ( param : ContextualType < T > ) {
11
+ }
12
+ }
13
+
14
+ class C extends CBase < string > {
15
+ constructor ( ) {
16
+ // Should be okay.
17
+ // 'p' should have type 'string'.
18
+ super ( {
19
+ method ( p ) {
20
+ p . length ;
21
+ }
22
+ } ) ;
23
+
24
+ // Should be okay.
25
+ // 'p' should have type 'string'.
26
+ super . foo ( {
27
+ method ( p ) {
28
+ p . length ;
29
+ }
30
+ } ) ;
31
+ }
32
+ }
33
+
34
+ //// [superCallParameterContextualTyping3.js]
35
+ var __extends = this . __extends || function ( d , b ) {
36
+ for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ;
37
+ function __ ( ) { this . constructor = d ; }
38
+ __ . prototype = b . prototype ;
39
+ d . prototype = new __ ( ) ;
40
+ } ;
41
+ var CBase = ( function ( ) {
42
+ function CBase ( param ) {
43
+ }
44
+ CBase . prototype . foo = function ( param ) {
45
+ } ;
46
+ return CBase ;
47
+ } ) ( ) ;
48
+ var C = ( function ( _super ) {
49
+ __extends ( C , _super ) ;
50
+ function C ( ) {
51
+ // Should be okay.
52
+ // 'p' should have type 'string'.
53
+ _super . call ( this , {
54
+ method : function ( p ) {
55
+ p . length ;
56
+ }
57
+ } ) ;
58
+ // Should be okay.
59
+ // 'p' should have type 'string'.
60
+ _super . prototype . foo . call ( this , {
61
+ method : function ( p ) {
62
+ p . length ;
63
+ }
64
+ } ) ;
65
+ }
66
+ return C ;
67
+ } ) ( CBase ) ;
Original file line number Diff line number Diff line change
1
+ === tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts ===
2
+ interface ContextualType<T> {
3
+ >ContextualType : ContextualType<T>
4
+ >T : T
5
+
6
+ method(parameter: T): void;
7
+ >method : (parameter: T) => void
8
+ >parameter : T
9
+ >T : T
10
+ }
11
+
12
+ class CBase<T> {
13
+ >CBase : CBase<T>
14
+ >T : T
15
+
16
+ constructor(param: ContextualType<T>) {
17
+ >param : ContextualType<T>
18
+ >ContextualType : ContextualType<T>
19
+ >T : T
20
+ }
21
+
22
+ foo(param: ContextualType<T>) {
23
+ >foo : (param: ContextualType<T>) => void
24
+ >param : ContextualType<T>
25
+ >ContextualType : ContextualType<T>
26
+ >T : T
27
+ }
28
+ }
29
+
30
+ class C extends CBase<string> {
31
+ >C : C
32
+ >CBase : CBase<T>
33
+
34
+ constructor() {
35
+ // Should be okay.
36
+ // 'p' should have type 'string'.
37
+ super({
38
+ >super({ method(p) { p.length; } }) : void
39
+ >super : typeof CBase
40
+ >{ method(p) { p.length; } } : { method(p: string): void; }
41
+
42
+ method(p) {
43
+ >method : (p: string) => void
44
+ >p : string
45
+
46
+ p.length;
47
+ >p.length : number
48
+ >p : string
49
+ >length : number
50
+ }
51
+ });
52
+
53
+ // Should be okay.
54
+ // 'p' should have type 'string'.
55
+ super.foo({
56
+ >super.foo({ method(p) { p.length; } }) : void
57
+ >super.foo : (param: ContextualType<string>) => void
58
+ >super : CBase<string>
59
+ >foo : (param: ContextualType<string>) => void
60
+ >{ method(p) { p.length; } } : { method(p: string): void; }
61
+
62
+ method(p) {
63
+ >method : (p: string) => void
64
+ >p : string
65
+
66
+ p.length;
67
+ >p.length : number
68
+ >p : string
69
+ >length : number
70
+ }
71
+ });
72
+ }
73
+ }
Original file line number Diff line number Diff line change
1
+ interface ContextualType < T > {
2
+ method ( parameter : T ) : void ;
3
+ }
4
+
5
+ class CBase < T > {
6
+ constructor ( param : ContextualType < T > ) {
7
+ }
8
+
9
+ foo ( param : ContextualType < T > ) {
10
+ }
11
+ }
12
+
13
+ class C extends CBase < string > {
14
+ constructor ( ) {
15
+ // Should be okay.
16
+ // 'p' should have type 'string'.
17
+ super ( {
18
+ method ( p ) {
19
+ p . length ;
20
+ }
21
+ } ) ;
22
+
23
+ // Should be okay.
24
+ // 'p' should have type 'string'.
25
+ super . foo ( {
26
+ method ( p ) {
27
+ p . length ;
28
+ }
29
+ } ) ;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments