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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient.
tests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'.
tests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'.
tests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'.
Property 'x' is missing in type '{}'.
==== tests/cases/compiler/contextualTyping.ts (4 errors) ====
// DEFAULT INTERFACES
interface IFoo {
n: number;
s: string;
f(i: number, s: string): string;
a: number[];
}
interface IBar {
foo: IFoo;
}
// CONTEXT: Class property declaration
class C1T5 {
foo: (i: number, s: string) => number = function(i) {
return i;
}
}
// CONTEXT: Module property declaration
module C2T5 {
export var foo: (i: number, s: string) => number = function(i) {
return i;
}
}
// CONTEXT: Variable declaration
var c3t1: (s: string) => string = (function(s) { return s });
var c3t2 = <IFoo>({
n: 1
})
var c3t3: number[] = [];
var c3t4: () => IFoo = function() { return <IFoo>({}) };
var c3t5: (n: number) => IFoo = function(n) { return <IFoo>({}) };
var c3t6: (n: number, s: string) => IFoo = function(n, s) { return <IFoo>({}) };
var c3t7: {
(n: number): number;
(s1: string): number;
} = function(n) { return n; };
var c3t8: (n: number, s: string) => number = function(n) { return n; };
var c3t9: number[][] = [[],[]];
var c3t10: IFoo[] = [<IFoo>({}),<IFoo>({})];
var c3t11: {(n: number, s: string): string;}[] = [function(n, s) { return s; }];
var c3t12: IBar = {
foo: <IFoo>({})
}
var c3t13 = <IFoo>({
f: function(i, s) { return s; }
})
var c3t14 = <IFoo>({
a: []
})
// CONTEXT: Class property assignment
class C4T5 {
foo: (i: number, s: string) => string;
constructor() {
this.foo = function(i, s) {
return s;
}
}
}
// CONTEXT: Module property assignment
module C5T5 {
export var foo: (i: number, s: string) => string;
foo = function(i, s) {
return s;
}
}
// CONTEXT: Variable assignment
var c6t5: (n: number) => IFoo;
c6t5 = <(n: number) => IFoo>function(n) { return <IFoo>({}) };
// CONTEXT: Array index assignment
var c7t2: IFoo[];
c7t2[0] = <IFoo>({n: 1});
// CONTEXT: Object property assignment
interface IPlaceHolder {
t1: (s: string) => string;
t2: IFoo;
t3: number[];
t4: () => IFoo;
t5: (n: number) => IFoo;
t6: (n: number, s: string) => IFoo;
t7: {
(n: number, s: string): number;
//(s1: string, s2: string): number;
};
t8: (n: number, s: string) => number;
t9: number[][];
t10: IFoo[];
t11: {(n: number, s: string): string;}[];
t12: IBar;
t13: IFoo;
t14: IFoo;
}
var objc8: {
t1: (s: string) => string;
t2: IFoo;
t3: number[];
t4: () => IFoo;
t5: (n: number) => IFoo;
t6: (n: number, s: string) => IFoo;
t7: {
(n: number, s: string): number;
//(s1: string, s2: string): number;
};
t8: (n: number, s: string) => number;
t9: number[][];
t10: IFoo[];
t11: {(n: number, s: string): string;}[];
t12: IBar;
t13: IFoo;
t14: IFoo;
} = <IPlaceHolder>({});
objc8.t1 = (function(s) { return s });
objc8.t2 = <IFoo>({
n: 1
});
objc8.t3 = [];
objc8.t4 = function() { return <IFoo>({}) };
objc8.t5 = function(n) { return <IFoo>({}) };
objc8.t6 = function(n, s) { return <IFoo>({}) };
objc8.t7 = function(n: number) { return n };
objc8.t8 = function(n) { return n; };
objc8.t9 = [[],[]];
objc8.t10 = [<IFoo>({}),<IFoo>({})];
objc8.t11 = [function(n, s) { return s; }];
objc8.t12 = {
foo: <IFoo>({})
}
objc8.t13 = <IFoo>({
f: function(i, s) { return s; }
})
objc8.t14 = <IFoo>({
a: []
})
// CONTEXT: Function call
function c9t5(f: (n: number) => IFoo) {};
c9t5(function(n) {
return <IFoo>({});
});
// CONTEXT: Return statement
var c10t5: () => (n: number) => IFoo = function() { return function(n) { return <IFoo>({}) } };
// CONTEXT: Newing a class
class C11t5 { constructor(f: (n: number) => IFoo) { } };
var i = new C11t5(function(n) { return <IFoo>({}) });
// CONTEXT: Type annotated expression
var c12t1 = <(s: string) => string> (function(s) { return s });
var c12t2 = <IFoo> ({
n: 1
});
var c12t3 = <number[]> [];
var c12t4 = <() => IFoo> function() { return <IFoo>({}) };
var c12t5 = <(n: number) => IFoo> function(n) { return <IFoo>({}) };
var c12t6 = <(n: number, s: string) => IFoo> function(n, s) { return <IFoo>({}) };
var c12t7 = <{
(n: number, s: string): number;
//(s1: string, s2: string): number;
}> function(n:number) { return n };
var c12t8 = <(n: number, s: string) => number> function(n) { return n; };
var c12t9 = <number[][]> [[],[]];
var c12t10 = <IFoo[]> [<IFoo>({}),<IFoo>({})];
var c12t11 = <{(n: number, s: string): string;}[]> [function(n, s) { return s; }];
var c12t12 = <IBar> {
foo: <IFoo>({})
}
var c12t13 = <IFoo> ({
f: function(i, s) { return s; }
})
var c12t14 = <IFoo> ({
a: []
})
// CONTEXT: Contextual typing declarations
// contextually typing function declarations
declare function EF1(a:number, b:number):number;
~~~
!!! error TS2384: Overload signatures must all be ambient or non-ambient.
function EF1(a,b) { return a+b; }
var efv = EF1(1,2);
// contextually typing from ambient class declarations
declare class Point
~~~~~
!!! error TS2300: Duplicate identifier 'Point'.
{
constructor(x: number, y: number);
x: number;
y: number;
add(dx: number, dy: number): Point;
static origin: Point;
}
function Point(x, y) {
~~~~~
!!! error TS2300: Duplicate identifier 'Point'.
this.x = x;
this.y = y;
return this;
}
Point.origin = new Point(0, 0);
Point.prototype.add = function(dx, dy) {
return new Point(this.x + dx, this.y + dy);
};
Point.prototype = {
x: 0,
y: 0,
add: function(dx, dy) {
return new Point(this.x + dx, this.y + dy);
}
};
interface A { x: string; }
interface B extends A { }
var x: B = { };
~
!!! error TS2322: Type '{}' is not assignable to type 'B'.
!!! error TS2322: Property 'x' is missing in type '{}'.
|