@@ -169,8 +169,8 @@ describe("verify", function () {
169
169
verifyAndAssertMessages ( [
170
170
"import type Foo from 'foo';" ,
171
171
"import type Foo2 from 'foo';" ,
172
- "function log<Foo, Foo2>( ) {}" ,
173
- "log( );"
172
+ "function log<T1, T2>(a: T1, b: T2 ) { return a + b; }" ,
173
+ "log<Foo, Foo2>(1, 2 );"
174
174
] . join ( "\n" ) ,
175
175
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
176
176
[ ]
@@ -276,9 +276,8 @@ describe("verify", function () {
276
276
it ( "type alias with type parameters" , function ( ) {
277
277
verifyAndAssertMessages ( [
278
278
"import type Bar from 'foo';" ,
279
- "import type Foo2 from 'foo';" ,
280
279
"import type Foo3 from 'foo';" ,
281
- "type Foo<Foo2 > = Bar<Foo3>" ,
280
+ "type Foo<T > = Bar<T, Foo3>" ,
282
281
"var x : Foo = 1; x;"
283
282
] . join ( "\n" ) ,
284
283
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
@@ -316,6 +315,62 @@ describe("verify", function () {
316
315
) ;
317
316
} ) ;
318
317
318
+ it ( "polymorphpic/generic types for class #123" , function ( ) {
319
+ verifyAndAssertMessages ( [
320
+ "class Box<T> {" ,
321
+ "value: T;" ,
322
+ "}" ,
323
+ "var box = new Box();" ,
324
+ "console.log(box.value);"
325
+ ] . join ( "\n" ) ,
326
+ { "no-unused-vars" : 1 , "no-undef" : 1 } ,
327
+ [ ]
328
+ ) ;
329
+ } ) ;
330
+
331
+ it ( "polymorphpic/generic types for function #123" , function ( ) {
332
+ verifyAndAssertMessages ( [
333
+ "export function identity<T>(value) {" ,
334
+ "var a: T = value; a;" ,
335
+ "}"
336
+ ] . join ( "\n" ) ,
337
+ { "no-unused-vars" : 1 , "no-undef" : 1 } ,
338
+ [ ]
339
+ ) ;
340
+ } ) ;
341
+
342
+ it ( "polymorphpic/generic types for type alias #123" , function ( ) {
343
+ verifyAndAssertMessages ( [
344
+ "import Bar from './Bar';" ,
345
+ "type Foo<T> = Bar<T>; var x: Foo = 1; x++"
346
+ ] . join ( "\n" ) ,
347
+ { "no-unused-vars" : 1 , "no-undef" : 1 } ,
348
+ [ ]
349
+ ) ;
350
+ } ) ;
351
+
352
+ it ( "polymorphpic/generic types - outside of fn scope #123" , function ( ) {
353
+ verifyAndAssertMessages ( [
354
+ "export function foo<T>(value) {" ,
355
+ "};" ,
356
+ "var b: T = 1; b;"
357
+ ] . join ( "\n" ) ,
358
+ { "no-unused-vars" : 1 , "no-undef" : 1 } ,
359
+ [ '1:20 T is defined but never used no-unused-vars' ,
360
+ '3:7 "T" is not defined. no-undef' ]
361
+ ) ;
362
+ } ) ;
363
+
364
+ it ( "polymorphpic/generic types - extending unknown #123" , function ( ) {
365
+ verifyAndAssertMessages ( [
366
+ "import Bar from 'bar';" ,
367
+ "export class Foo extends Bar<T> {}" ,
368
+ ] . join ( "\n" ) ,
369
+ { "no-unused-vars" : 1 , "no-undef" : 1 } ,
370
+ [ '2:29 "T" is not defined. no-undef' ]
371
+ ) ;
372
+ } ) ;
373
+
319
374
it ( "1" , function ( ) {
320
375
verifyAndAssertMessages (
321
376
[
@@ -413,9 +468,7 @@ describe("verify", function () {
413
468
it ( "9" , function ( ) {
414
469
verifyAndAssertMessages (
415
470
[
416
- "import type Foo from 'foo';" ,
417
- "import type Foo2 from 'foo';" ,
418
- "export default function <Foo, Foo2>() {}"
471
+ "export default function <T1, T2>(a: T1, b: T2) {}"
419
472
] . join ( "\n" ) ,
420
473
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
421
474
[ ]
@@ -425,9 +478,7 @@ describe("verify", function () {
425
478
it ( "10" , function ( ) {
426
479
verifyAndAssertMessages (
427
480
[
428
- "import type Foo from 'foo';" ,
429
- "import type Foo2 from 'foo';" ,
430
- "var a=function<Foo,Foo2>() {}; a;"
481
+ "var a=function<T1,T2>(a: T1, b: T2) {return a + b;}; a;"
431
482
] . join ( "\n" ) ,
432
483
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
433
484
[ ]
@@ -437,10 +488,7 @@ describe("verify", function () {
437
488
it ( "11" , function ( ) {
438
489
verifyAndAssertMessages (
439
490
[
440
- "import type Foo from 'foo';" ,
441
- "import type Foo2 from 'foo';" ,
442
- "import type Foo3 from 'foo';" ,
443
- "var a={*id<Foo>(x: Foo2): Foo3 { x; }}; a;"
491
+ "var a={*id<T>(x: T): T { x; }}; a;"
444
492
] . join ( "\n" ) ,
445
493
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
446
494
[ ]
@@ -450,10 +498,7 @@ describe("verify", function () {
450
498
it ( "12" , function ( ) {
451
499
verifyAndAssertMessages (
452
500
[
453
- "import type Foo from 'foo';" ,
454
- "import type Foo2 from 'foo';" ,
455
- "import type Foo3 from 'foo';" ,
456
- "var a={async id<Foo>(x: Foo2): Foo3 { x; }}; a;"
501
+ "var a={async id<T>(x: T): T { x; }}; a;"
457
502
] . join ( "\n" ) ,
458
503
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
459
504
[ ]
@@ -463,10 +508,7 @@ describe("verify", function () {
463
508
it ( "13" , function ( ) {
464
509
verifyAndAssertMessages (
465
510
[
466
- "import type Foo from 'foo';" ,
467
- "import type Foo2 from 'foo';" ,
468
- "import type Foo3 from 'foo';" ,
469
- "var a={123<Foo>(x: Foo2): Foo3 { x; }}; a;"
511
+ "var a={123<T>(x: T): T { x; }}; a;"
470
512
] . join ( "\n" ) ,
471
513
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
472
514
[ ]
@@ -597,10 +639,8 @@ describe("verify", function () {
597
639
it ( "24" , function ( ) {
598
640
verifyAndAssertMessages (
599
641
[
600
- "import type Foo from 'foo';" ,
601
- "import type Foo2 from 'foo';" ,
602
- "import Baz from 'foo';" ,
603
- "export default class Bar<Foo> extends Baz<Foo2> { };"
642
+ "import type Baz from 'baz';" ,
643
+ "export default class Bar<T> extends Baz<T> { };"
604
644
] . join ( "\n" ) ,
605
645
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
606
646
[ ]
@@ -610,10 +650,7 @@ describe("verify", function () {
610
650
it ( "25" , function ( ) {
611
651
verifyAndAssertMessages (
612
652
[
613
- "import type Foo from 'foo';" ,
614
- "import type Foo2 from 'foo';" ,
615
- "import type Foo3 from 'foo';" ,
616
- "export default class Bar<Foo> { bar<Foo2>():Foo3 { return 42; }}"
653
+ "export default class Bar<T> { bar(): T { return 42; }}"
617
654
] . join ( "\n" ) ,
618
655
{ "no-unused-vars" : 1 , "no-undef" : 1 } ,
619
656
[ ]
0 commit comments