Merge branch 'master' into completionFixes

This commit is contained in:
Mohamed Hegazy
2014-10-28 09:10:03 -07:00
49 changed files with 636 additions and 332 deletions

View File

@@ -1,6 +1,6 @@
function foo<T>(n: { x: T; y: T }, m: T) { return m; }
var x = foo({ x: 3, y: "" }, 4); // no error, x is Object, the best common type
// these are all errors
var x = foo({ x: 3, y: "" }, 4);
var x2 = foo<number>({ x: 3, y: "" }, 4);
var x3 = foo<string>({ x: 3, y: "" }, 4);
var x4 = foo<number>({ x: "", y: 4 }, "");

View File

@@ -11,11 +11,11 @@ declare function foo(arg: (x: D) => number): string;
declare function foo(arg: (x: C) => any): string;
declare function foo(arg: (x: B) => any): number;
var result: number = foo(x => new G(x)); // No error, returns number
var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
var result2: number = foo(x => new G<typeof x>(x)); // No error, returns number
var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
var result3: string = foo(x => { // returns string because the C overload is picked
var y: G<typeof x>; // error that C does not satisfy constraint
var result3: string = foo(x => { // x has type D
var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
return y;
});

View File

@@ -0,0 +1,4 @@
declare function f<T extends Number>(x: T): T;
declare function f<T extends String>(x: T): T
var v = f<string>("");

View File

@@ -15,7 +15,7 @@ function f<T extends Base>(a: { x: T; y: T }) {
return r;
}
var r1 = f({ x: new Derived(), y: new Derived2() }); // ok, both extend Base
var r1 = f({ x: new Derived(), y: new Derived2() }); // error because neither is supertype of the other
function f2<T extends Base, U extends { x: T; y: T }>(a: U) {
var r: T;
@@ -30,7 +30,7 @@ function f3<T extends Base>(y: (a: T) => T, x: T) {
return y(null);
}
// all ok - T gets fixed too early, but then defaults to Base and everything works out
// all ok - second argument is processed before x is fixed
var r4 = f3(x => x, new Base());
var r5 = f3(x => x, new Derived());
var r6 = f3(x => x, null);

View File

@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
////class ABCD {
//// constructor(private x: number, public y: number, private [|z|]: number) {
//// }
////
//// func() {
//// return this.[|z|];
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.referencesAtPositionContains(range);
});
});