Add test case

This commit is contained in:
Nathan Shively-Sanders 2016-05-23 15:11:03 -07:00
parent 0a54a3b50e
commit cd97270721
3 changed files with 89 additions and 14 deletions

View file

@ -1,9 +1,7 @@
tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(3,7): error TS2339: Property 'blah' does not exist on type 'T'.
tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(9,7): error TS2339: Property 'blah' does not exist on type 'T'.
tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(10,7): error TS2339: Property 'toString' does not exist on type 'T'.
==== tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts (3 errors) ====
==== tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts (1 errors) ====
function fee<T>() {
var t: T;
t.blah; // Error
@ -14,10 +12,28 @@ tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(10,7): error TS2339: P
function fee2<T extends any>() {
var t: T;
t.blah; // Error
~~~~
!!! error TS2339: Property 'blah' does not exist on type 'T'.
t.blah; // ok
t.toString; // ok
~~~~~~~~
!!! error TS2339: Property 'toString' does not exist on type 'T'.
}
}
function f<T extends any>(x: T) {
x.children;
x();
new x();
x[100];
x['hello'];
}
// Generic Tree structure
type Tree<T> = T & {
children?: Tree<T>[];
}
class MyClass {
public static displayTree1<T extends Tree<any>>(tree: T) {
// error "Property 'children' does not exist on type 'T'"
tree.children;
}
}

View file

@ -7,9 +7,31 @@ function fee<T>() {
function fee2<T extends any>() {
var t: T;
t.blah; // Error
t.blah; // ok
t.toString; // ok
}
}
function f<T extends any>(x: T) {
x.children;
x();
new x();
x[100];
x['hello'];
}
// Generic Tree structure
type Tree<T> = T & {
children?: Tree<T>[];
}
class MyClass {
public static displayTree1<T extends Tree<any>>(tree: T) {
// error "Property 'children' does not exist on type 'T'"
tree.children;
}
}
//// [typeParameterExplicitlyExtendsAny.js]
function fee() {
@ -19,6 +41,22 @@ function fee() {
}
function fee2() {
var t;
t.blah; // Error
t.blah; // ok
t.toString; // ok
}
function f(x) {
x.children;
x();
new x();
x[100];
x['hello'];
}
var MyClass = (function () {
function MyClass() {
}
MyClass.displayTree1 = function (tree) {
// error "Property 'children' does not exist on type 'T'"
tree.children;
};
return MyClass;
}());

View file

@ -6,6 +6,27 @@ function fee<T>() {
function fee2<T extends any>() {
var t: T;
t.blah; // Error
t.blah; // ok
t.toString; // ok
}
}
function f<T extends any>(x: T) {
x.children;
x();
new x();
x[100];
x['hello'];
}
// Generic Tree structure
type Tree<T> = T & {
children?: Tree<T>[];
}
class MyClass {
public static displayTree1<T extends Tree<any>>(tree: T) {
// error "Property 'children' does not exist on type 'T'"
tree.children;
}
}