mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into reuseAndCache
This commit is contained in:
@@ -112,7 +112,7 @@ exports.delint = delint;
|
||||
var fileNames = process.argv.slice(2);
|
||||
fileNames.forEach(function (fileName) {
|
||||
// Parse a file
|
||||
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ES6 */, true);
|
||||
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ES6 */, /*setParentNodes */ true);
|
||||
// delint it
|
||||
delint(sourceFile);
|
||||
});
|
||||
|
||||
@@ -22,8 +22,8 @@ System.register(['foo'], function(exports_1) {
|
||||
var cls, cls2, x, y, z, M;
|
||||
return {
|
||||
setters:[
|
||||
function (_alias) {
|
||||
alias = _alias;
|
||||
function (alias_1) {
|
||||
alias = alias_1;
|
||||
}],
|
||||
execute: function() {
|
||||
cls = alias.Class;
|
||||
|
||||
@@ -21,8 +21,8 @@ System.register(["foo"], function(exports_1) {
|
||||
var cls, cls2, x, y, z, M;
|
||||
return {
|
||||
setters:[
|
||||
function (_foo_1) {
|
||||
foo_1 = _foo_1;
|
||||
function (foo_1_1) {
|
||||
foo_1 = foo_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
cls = foo_1.alias.Class;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAssignabilityConstructorFunction.ts(7,1): error TS2322: Type 'typeof A' is not assignable to type 'new () => A'.
|
||||
Cannot assign an abstract constructor type to a non-abstract constructor type.
|
||||
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAssignabilityConstructorFunction.ts(8,1): error TS2322: Type 'string' is not assignable to type 'new () => A'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAssignabilityConstructorFunction.ts (2 errors) ====
|
||||
abstract class A { }
|
||||
|
||||
// var AA: typeof A;
|
||||
var AAA: new() => A;
|
||||
|
||||
// AA = A; // okay
|
||||
AAA = A; // error.
|
||||
~~~
|
||||
!!! error TS2322: Type 'typeof A' is not assignable to type 'new () => A'.
|
||||
!!! error TS2322: Cannot assign an abstract constructor type to a non-abstract constructor type.
|
||||
AAA = "asdf";
|
||||
~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'new () => A'.
|
||||
@@ -0,0 +1,21 @@
|
||||
//// [classAbstractAssignabilityConstructorFunction.ts]
|
||||
abstract class A { }
|
||||
|
||||
// var AA: typeof A;
|
||||
var AAA: new() => A;
|
||||
|
||||
// AA = A; // okay
|
||||
AAA = A; // error.
|
||||
AAA = "asdf";
|
||||
|
||||
//// [classAbstractAssignabilityConstructorFunction.js]
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
})();
|
||||
// var AA: typeof A;
|
||||
var AAA;
|
||||
// AA = A; // okay
|
||||
AAA = A; // error.
|
||||
AAA = "asdf";
|
||||
@@ -8,4 +8,5 @@ s.map(// do something
|
||||
//// [commentInMethodCall.js]
|
||||
//commment here
|
||||
var s;
|
||||
s.map(function () { });
|
||||
s.map(// do something
|
||||
function () { });
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//// [commentsArgumentsOfCallExpression1.ts]
|
||||
function foo(/*c1*/ x: any) { }
|
||||
foo(/*c2*/ 1);
|
||||
foo(/*c3*/ function () { });
|
||||
foo(
|
||||
/*c4*/
|
||||
() => { });
|
||||
foo(
|
||||
/*c5*/
|
||||
/*c6*/
|
||||
() => { });
|
||||
foo(/*c7*/
|
||||
() => { });
|
||||
foo(
|
||||
/*c7*/
|
||||
/*c8*/() => { });
|
||||
|
||||
//// [commentsArgumentsOfCallExpression1.js]
|
||||
function foo(/*c1*/ x) { }
|
||||
foo(/*c2*/ 1);
|
||||
foo(/*c3*/ function () { });
|
||||
foo(
|
||||
/*c4*/
|
||||
function () { });
|
||||
foo(
|
||||
/*c5*/
|
||||
/*c6*/
|
||||
function () { });
|
||||
foo(/*c7*/ function () { });
|
||||
foo(
|
||||
/*c7*/
|
||||
/*c8*/ function () { });
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/compiler/commentsArgumentsOfCallExpression1.ts ===
|
||||
function foo(/*c1*/ x: any) { }
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(commentsArgumentsOfCallExpression1.ts, 0, 13))
|
||||
|
||||
foo(/*c2*/ 1);
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
foo(/*c3*/ function () { });
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
foo(
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
/*c4*/
|
||||
() => { });
|
||||
foo(
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
/*c5*/
|
||||
/*c6*/
|
||||
() => { });
|
||||
foo(/*c7*/
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
() => { });
|
||||
foo(
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression1.ts, 0, 0))
|
||||
|
||||
/*c7*/
|
||||
/*c8*/() => { });
|
||||
@@ -0,0 +1,47 @@
|
||||
=== tests/cases/compiler/commentsArgumentsOfCallExpression1.ts ===
|
||||
function foo(/*c1*/ x: any) { }
|
||||
>foo : (x: any) => void
|
||||
>x : any
|
||||
|
||||
foo(/*c2*/ 1);
|
||||
>foo(/*c2*/ 1) : void
|
||||
>foo : (x: any) => void
|
||||
>1 : number
|
||||
|
||||
foo(/*c3*/ function () { });
|
||||
>foo(/*c3*/ function () { }) : void
|
||||
>foo : (x: any) => void
|
||||
>function () { } : () => void
|
||||
|
||||
foo(
|
||||
>foo( /*c4*/ () => { }) : void
|
||||
>foo : (x: any) => void
|
||||
|
||||
/*c4*/
|
||||
() => { });
|
||||
>() => { } : () => void
|
||||
|
||||
foo(
|
||||
>foo( /*c5*/ /*c6*/ () => { }) : void
|
||||
>foo : (x: any) => void
|
||||
|
||||
/*c5*/
|
||||
/*c6*/
|
||||
() => { });
|
||||
>() => { } : () => void
|
||||
|
||||
foo(/*c7*/
|
||||
>foo(/*c7*/ () => { }) : void
|
||||
>foo : (x: any) => void
|
||||
|
||||
() => { });
|
||||
>() => { } : () => void
|
||||
|
||||
foo(
|
||||
>foo( /*c7*/ /*c8*/() => { }) : void
|
||||
>foo : (x: any) => void
|
||||
|
||||
/*c7*/
|
||||
/*c8*/() => { });
|
||||
>() => { } : () => void
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [commentsArgumentsOfCallExpression2.ts]
|
||||
function foo(/*c1*/ x: any, /*d1*/ y: any,/*e1*/w?: any) { }
|
||||
var a, b: any;
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
|
||||
foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
|
||||
foo(
|
||||
/*c4*/ function () { },
|
||||
/*d4*/() => { },
|
||||
/*e4*/
|
||||
/*e5*/ "hello");
|
||||
|
||||
//// [commentsArgumentsOfCallExpression2.js]
|
||||
function foo(/*c1*/ x, /*d1*/ y, /*e1*/ w) { }
|
||||
var a, b;
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d2*/ function () { }, /*e2*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d3*/ function () { }, /*e3*/ (a + b));
|
||||
foo(
|
||||
/*c4*/ function () { },
|
||||
/*d4*/ function () { },
|
||||
/*e4*/
|
||||
/*e5*/ "hello");
|
||||
@@ -0,0 +1,33 @@
|
||||
=== tests/cases/compiler/commentsArgumentsOfCallExpression2.ts ===
|
||||
function foo(/*c1*/ x: any, /*d1*/ y: any,/*e1*/w?: any) { }
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression2.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(commentsArgumentsOfCallExpression2.ts, 0, 13))
|
||||
>y : Symbol(y, Decl(commentsArgumentsOfCallExpression2.ts, 0, 27))
|
||||
>w : Symbol(w, Decl(commentsArgumentsOfCallExpression2.ts, 0, 42))
|
||||
|
||||
var a, b: any;
|
||||
>a : Symbol(a, Decl(commentsArgumentsOfCallExpression2.ts, 1, 3))
|
||||
>b : Symbol(b, Decl(commentsArgumentsOfCallExpression2.ts, 1, 6))
|
||||
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression2.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(commentsArgumentsOfCallExpression2.ts, 1, 3))
|
||||
>b : Symbol(b, Decl(commentsArgumentsOfCallExpression2.ts, 1, 6))
|
||||
|
||||
foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression2.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(commentsArgumentsOfCallExpression2.ts, 1, 3))
|
||||
>b : Symbol(b, Decl(commentsArgumentsOfCallExpression2.ts, 1, 6))
|
||||
|
||||
foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression2.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(commentsArgumentsOfCallExpression2.ts, 1, 3))
|
||||
>b : Symbol(b, Decl(commentsArgumentsOfCallExpression2.ts, 1, 6))
|
||||
|
||||
foo(
|
||||
>foo : Symbol(foo, Decl(commentsArgumentsOfCallExpression2.ts, 0, 0))
|
||||
|
||||
/*c4*/ function () { },
|
||||
/*d4*/() => { },
|
||||
/*e4*/
|
||||
/*e5*/ "hello");
|
||||
@@ -0,0 +1,55 @@
|
||||
=== tests/cases/compiler/commentsArgumentsOfCallExpression2.ts ===
|
||||
function foo(/*c1*/ x: any, /*d1*/ y: any,/*e1*/w?: any) { }
|
||||
>foo : (x: any, y: any, w?: any) => void
|
||||
>x : any
|
||||
>y : any
|
||||
>w : any
|
||||
|
||||
var a, b: any;
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
>foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b) : void
|
||||
>foo : (x: any, y: any, w?: any) => void
|
||||
>1 : number
|
||||
>1 + 2 : number
|
||||
>1 : number
|
||||
>2 : number
|
||||
>a + b : any
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
|
||||
>foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b) : void
|
||||
>foo : (x: any, y: any, w?: any) => void
|
||||
>function () { } : () => void
|
||||
>() => { } : () => void
|
||||
>a + /*e3*/ b : any
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
|
||||
>foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)) : void
|
||||
>foo : (x: any, y: any, w?: any) => void
|
||||
>function () { } : () => void
|
||||
>() => { } : () => void
|
||||
>(a + b) : any
|
||||
>a + b : any
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
foo(
|
||||
>foo( /*c4*/ function () { }, /*d4*/() => { }, /*e4*/ /*e5*/ "hello") : void
|
||||
>foo : (x: any, y: any, w?: any) => void
|
||||
|
||||
/*c4*/ function () { },
|
||||
>function () { } : () => void
|
||||
|
||||
/*d4*/() => { },
|
||||
>() => { } : () => void
|
||||
|
||||
/*e4*/
|
||||
/*e5*/ "hello");
|
||||
>"hello" : string
|
||||
|
||||
@@ -6,5 +6,5 @@ var v = {
|
||||
|
||||
//// [commentsBeforeFunctionExpression1.js]
|
||||
var v = {
|
||||
f: function (a) { return 0; }
|
||||
f: /**own f*/ function (a) { return 0; }
|
||||
};
|
||||
|
||||
@@ -89,7 +89,7 @@ var i2_i_nc_fnfoo = i2_i.nc_fnfoo;
|
||||
var i2_i_nc_fnfoo_r = i2_i.nc_fnfoo(10);
|
||||
var i3_i;
|
||||
i3_i = {
|
||||
f: function (/**i3_i a*/ a) { return "Hello" + a; },
|
||||
f: /**own f*/ function (/**i3_i a*/ a) { return "Hello" + a; },
|
||||
l: this.f,
|
||||
/** own x*/
|
||||
x: this.f(10),
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [commentsOnPropertyOfObjectLiteral1.ts]
|
||||
var resolve = {
|
||||
id: /*! @ngInject */ (details: any) => details.id,
|
||||
id1: /* c1 */ "hello",
|
||||
id2:
|
||||
/*! @ngInject */ (details: any) => details.id,
|
||||
id3:
|
||||
/*! @ngInject */
|
||||
(details: any) => details.id,
|
||||
id4:
|
||||
/*! @ngInject */
|
||||
/* C2 */
|
||||
(details: any) => details.id,
|
||||
};
|
||||
|
||||
//// [commentsOnPropertyOfObjectLiteral1.js]
|
||||
var resolve = {
|
||||
id: /*! @ngInject */ function (details) { return details.id; },
|
||||
id1: /* c1 */ "hello",
|
||||
id2:
|
||||
/*! @ngInject */ function (details) { return details.id; },
|
||||
id3:
|
||||
/*! @ngInject */
|
||||
function (details) { return details.id; },
|
||||
id4:
|
||||
/*! @ngInject */
|
||||
/* C2 */
|
||||
function (details) { return details.id; }
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
=== tests/cases/compiler/commentsOnPropertyOfObjectLiteral1.ts ===
|
||||
var resolve = {
|
||||
>resolve : Symbol(resolve, Decl(commentsOnPropertyOfObjectLiteral1.ts, 0, 3))
|
||||
|
||||
id: /*! @ngInject */ (details: any) => details.id,
|
||||
>id : Symbol(id, Decl(commentsOnPropertyOfObjectLiteral1.ts, 0, 15))
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 1, 26))
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 1, 26))
|
||||
|
||||
id1: /* c1 */ "hello",
|
||||
>id1 : Symbol(id1, Decl(commentsOnPropertyOfObjectLiteral1.ts, 1, 54))
|
||||
|
||||
id2:
|
||||
>id2 : Symbol(id2, Decl(commentsOnPropertyOfObjectLiteral1.ts, 2, 26))
|
||||
|
||||
/*! @ngInject */ (details: any) => details.id,
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 4, 26))
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 4, 26))
|
||||
|
||||
id3:
|
||||
>id3 : Symbol(id3, Decl(commentsOnPropertyOfObjectLiteral1.ts, 4, 54))
|
||||
|
||||
/*! @ngInject */
|
||||
(details: any) => details.id,
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 7, 5))
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 7, 5))
|
||||
|
||||
id4:
|
||||
>id4 : Symbol(id4, Decl(commentsOnPropertyOfObjectLiteral1.ts, 7, 33))
|
||||
|
||||
/*! @ngInject */
|
||||
/* C2 */
|
||||
(details: any) => details.id,
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 11, 5))
|
||||
>details : Symbol(details, Decl(commentsOnPropertyOfObjectLiteral1.ts, 11, 5))
|
||||
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
=== tests/cases/compiler/commentsOnPropertyOfObjectLiteral1.ts ===
|
||||
var resolve = {
|
||||
>resolve : { id: (details: any) => any; id1: string; id2: (details: any) => any; id3: (details: any) => any; id4: (details: any) => any; }
|
||||
>{ id: /*! @ngInject */ (details: any) => details.id, id1: /* c1 */ "hello", id2: /*! @ngInject */ (details: any) => details.id, id3: /*! @ngInject */ (details: any) => details.id, id4: /*! @ngInject */ /* C2 */ (details: any) => details.id,} : { id: (details: any) => any; id1: string; id2: (details: any) => any; id3: (details: any) => any; id4: (details: any) => any; }
|
||||
|
||||
id: /*! @ngInject */ (details: any) => details.id,
|
||||
>id : (details: any) => any
|
||||
>(details: any) => details.id : (details: any) => any
|
||||
>details : any
|
||||
>details.id : any
|
||||
>details : any
|
||||
>id : any
|
||||
|
||||
id1: /* c1 */ "hello",
|
||||
>id1 : string
|
||||
>"hello" : string
|
||||
|
||||
id2:
|
||||
>id2 : (details: any) => any
|
||||
|
||||
/*! @ngInject */ (details: any) => details.id,
|
||||
>(details: any) => details.id : (details: any) => any
|
||||
>details : any
|
||||
>details.id : any
|
||||
>details : any
|
||||
>id : any
|
||||
|
||||
id3:
|
||||
>id3 : (details: any) => any
|
||||
|
||||
/*! @ngInject */
|
||||
(details: any) => details.id,
|
||||
>(details: any) => details.id : (details: any) => any
|
||||
>details : any
|
||||
>details.id : any
|
||||
>details : any
|
||||
>id : any
|
||||
|
||||
id4:
|
||||
>id4 : (details: any) => any
|
||||
|
||||
/*! @ngInject */
|
||||
/* C2 */
|
||||
(details: any) => details.id,
|
||||
>(details: any) => details.id : (details: any) => any
|
||||
>details : any
|
||||
>details.id : any
|
||||
>details : any
|
||||
>id : any
|
||||
|
||||
};
|
||||
@@ -82,5 +82,7 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any
|
||||
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
|
||||
>IWithCallSignatures4 : Symbol(IWithCallSignatures4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 18, 1))
|
||||
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
|
||||
>a.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
|
||||
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any
|
||||
>x4 : IWithCallSignatures | IWithCallSignatures4
|
||||
>IWithCallSignatures : IWithCallSignatures
|
||||
>IWithCallSignatures4 : IWithCallSignatures4
|
||||
>a => /*here a should be any*/ a.toString() : (a: any) => any
|
||||
>a : any
|
||||
>a.toString() : any
|
||||
>a.toString : any
|
||||
>a : any
|
||||
>toString : any
|
||||
>a => /*here a should be any*/ a.toString() : (a: number) => string
|
||||
>a : number
|
||||
>a.toString() : string
|
||||
>a.toString : (radix?: number) => string
|
||||
>a : number
|
||||
>toString : (radix?: number) => string
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ function makePoint(x) {
|
||||
};
|
||||
}
|
||||
;
|
||||
var point = makePoint(2);
|
||||
var x = point.x;
|
||||
var /*4*/ point = makePoint(2);
|
||||
var /*2*/ x = point.x;
|
||||
point.x = 30;
|
||||
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ function makePoint(x) {
|
||||
};
|
||||
}
|
||||
;
|
||||
var point = makePoint(2);
|
||||
var x = point.x;
|
||||
var /*4*/ point = makePoint(2);
|
||||
var /*2*/ x = point.x;
|
||||
|
||||
|
||||
//// [declFileObjectLiteralWithOnlyGetter.d.ts]
|
||||
|
||||
@@ -17,7 +17,7 @@ function makePoint(x) {
|
||||
};
|
||||
}
|
||||
;
|
||||
var point = makePoint(2);
|
||||
var /*3*/ point = makePoint(2);
|
||||
point.x = 30;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//// [tests/cases/conformance/decorators/decoratorMetadata.ts] ////
|
||||
|
||||
//// [service.ts]
|
||||
export default class Service {
|
||||
}
|
||||
//// [component.ts]
|
||||
import Service from "./service";
|
||||
|
||||
declare var decorator: any;
|
||||
|
||||
@decorator
|
||||
class MyComponent {
|
||||
constructor(public Service: Service) {
|
||||
}
|
||||
}
|
||||
|
||||
//// [service.js]
|
||||
var Service = (function () {
|
||||
function Service() {
|
||||
}
|
||||
return Service;
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = Service;
|
||||
//// [component.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
|
||||
switch (arguments.length) {
|
||||
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
|
||||
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
|
||||
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
|
||||
}
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var MyComponent = (function () {
|
||||
function MyComponent(Service) {
|
||||
this.Service = Service;
|
||||
}
|
||||
MyComponent = __decorate([
|
||||
decorator,
|
||||
__metadata('design:paramtypes', [service_1.default])
|
||||
], MyComponent);
|
||||
return MyComponent;
|
||||
})();
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/conformance/decorators/service.ts ===
|
||||
export default class Service {
|
||||
>Service : Symbol(Service, Decl(service.ts, 0, 0))
|
||||
}
|
||||
=== tests/cases/conformance/decorators/component.ts ===
|
||||
import Service from "./service";
|
||||
>Service : Symbol(Service, Decl(component.ts, 0, 6))
|
||||
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(component.ts, 2, 11))
|
||||
|
||||
@decorator
|
||||
>decorator : Symbol(decorator, Decl(component.ts, 2, 11))
|
||||
|
||||
class MyComponent {
|
||||
>MyComponent : Symbol(MyComponent, Decl(component.ts, 2, 27))
|
||||
|
||||
constructor(public Service: Service) {
|
||||
>Service : Symbol(Service, Decl(component.ts, 6, 16))
|
||||
>Service : Symbol(Service, Decl(component.ts, 0, 6))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/conformance/decorators/service.ts ===
|
||||
export default class Service {
|
||||
>Service : Service
|
||||
}
|
||||
=== tests/cases/conformance/decorators/component.ts ===
|
||||
import Service from "./service";
|
||||
>Service : typeof Service
|
||||
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
@decorator
|
||||
>decorator : any
|
||||
|
||||
class MyComponent {
|
||||
>MyComponent : MyComponent
|
||||
|
||||
constructor(public Service: Service) {
|
||||
>Service : Service
|
||||
>Service : Service
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//// [tests/cases/conformance/classes/classExpressions/extendClassExpressionFromModule.ts] ////
|
||||
|
||||
//// [foo1.ts]
|
||||
class x{}
|
||||
|
||||
export = x;
|
||||
|
||||
//// [foo2.ts]
|
||||
import foo1 = require('./foo1');
|
||||
var x = foo1;
|
||||
class y extends x {}
|
||||
|
||||
|
||||
//// [foo1.js]
|
||||
var x = (function () {
|
||||
function x() {
|
||||
}
|
||||
return x;
|
||||
})();
|
||||
module.exports = x;
|
||||
//// [foo2.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var foo1 = require('./foo1');
|
||||
var x = foo1;
|
||||
var y = (function (_super) {
|
||||
__extends(y, _super);
|
||||
function y() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
return y;
|
||||
})(x);
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/conformance/classes/classExpressions/foo2.ts ===
|
||||
import foo1 = require('./foo1');
|
||||
>foo1 : Symbol(foo1, Decl(foo2.ts, 0, 0))
|
||||
|
||||
var x = foo1;
|
||||
>x : Symbol(x, Decl(foo2.ts, 1, 3))
|
||||
>foo1 : Symbol(foo1, Decl(foo2.ts, 0, 0))
|
||||
|
||||
class y extends x {}
|
||||
>y : Symbol(y, Decl(foo2.ts, 1, 13))
|
||||
|
||||
=== tests/cases/conformance/classes/classExpressions/foo1.ts ===
|
||||
class x{}
|
||||
>x : Symbol(x, Decl(foo1.ts, 0, 0))
|
||||
|
||||
export = x;
|
||||
>x : Symbol(x, Decl(foo1.ts, 0, 0))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/classes/classExpressions/foo2.ts ===
|
||||
import foo1 = require('./foo1');
|
||||
>foo1 : typeof foo1
|
||||
|
||||
var x = foo1;
|
||||
>x : typeof foo1
|
||||
>foo1 : typeof foo1
|
||||
|
||||
class y extends x {}
|
||||
>y : y
|
||||
>x : foo1
|
||||
|
||||
=== tests/cases/conformance/classes/classExpressions/foo1.ts ===
|
||||
class x{}
|
||||
>x : x
|
||||
|
||||
export = x;
|
||||
>x : x
|
||||
|
||||
@@ -29,21 +29,18 @@ var foo = (function () {
|
||||
return foo;
|
||||
})();
|
||||
var x;
|
||||
x = <any> {test}: <any></any> };
|
||||
x = <any> {test} <any></any> };
|
||||
|
||||
x = <any><any></any>;
|
||||
|
||||
x = <foo>hello {<foo>} </foo>};
|
||||
x = <foo>hello {<foo>} </foo>}
|
||||
|
||||
x = <foo test={<foo>}>hello</foo>}/>;
|
||||
x = <foo test={<foo>}>hello</foo>}/>
|
||||
|
||||
x = <foo test={<foo>}>hello{<foo>}</foo>};
|
||||
x = <foo test={<foo>}>hello{<foo>}</foo>}
|
||||
|
||||
x = <foo>x</foo>, x = <foo />;
|
||||
|
||||
<foo>{<foo><foo>{/foo/.test(x) ? <foo><foo></foo> : <foo><foo></foo>}</foo>}</foo>
|
||||
:
|
||||
}
|
||||
|
||||
|
||||
</></>}</></>}/></></></>;
|
||||
}</></>}</></>}/></></></>;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//// [jsxHash.tsx]
|
||||
var t02 = <a>{0}#</a>;
|
||||
var t03 = <a>#{0}</a>;
|
||||
var t04 = <a>#{0}#</a>;
|
||||
var t05 = <a>#<i></i></a>;
|
||||
var t06 = <a>#<i></i></a>;
|
||||
var t07 = <a>#<i>#</i></a>;
|
||||
var t08 = <a><i></i>#</a>;
|
||||
var t09 = <a>#<i></i>#</a>;
|
||||
var t10 = <a><i/>#</a>;
|
||||
var t11 = <a>#<i/></a>;
|
||||
var t12 = <a>#</a>;
|
||||
|
||||
|
||||
//// [jsxHash.jsx]
|
||||
var t02 = <a>{0}#</a>;
|
||||
var t03 = <a>#{0}</a>;
|
||||
var t04 = <a>#{0}#</a>;
|
||||
var t05 = <a>#<i></i></a>;
|
||||
var t06 = <a>#<i></i></a>;
|
||||
var t07 = <a>#<i>#</i></a>;
|
||||
var t08 = <a><i></i>#</a>;
|
||||
var t09 = <a>#<i></i>#</a>;
|
||||
var t10 = <a><i />#</a>;
|
||||
var t11 = <a>#<i /></a>;
|
||||
var t12 = <a>#</a>;
|
||||
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/compiler/jsxHash.tsx ===
|
||||
var t02 = <a>{0}#</a>;
|
||||
>t02 : Symbol(t02, Decl(jsxHash.tsx, 0, 3))
|
||||
|
||||
var t03 = <a>#{0}</a>;
|
||||
>t03 : Symbol(t03, Decl(jsxHash.tsx, 1, 3))
|
||||
|
||||
var t04 = <a>#{0}#</a>;
|
||||
>t04 : Symbol(t04, Decl(jsxHash.tsx, 2, 3))
|
||||
|
||||
var t05 = <a>#<i></i></a>;
|
||||
>t05 : Symbol(t05, Decl(jsxHash.tsx, 3, 3))
|
||||
|
||||
var t06 = <a>#<i></i></a>;
|
||||
>t06 : Symbol(t06, Decl(jsxHash.tsx, 4, 3))
|
||||
|
||||
var t07 = <a>#<i>#</i></a>;
|
||||
>t07 : Symbol(t07, Decl(jsxHash.tsx, 5, 3))
|
||||
|
||||
var t08 = <a><i></i>#</a>;
|
||||
>t08 : Symbol(t08, Decl(jsxHash.tsx, 6, 3))
|
||||
|
||||
var t09 = <a>#<i></i>#</a>;
|
||||
>t09 : Symbol(t09, Decl(jsxHash.tsx, 7, 3))
|
||||
|
||||
var t10 = <a><i/>#</a>;
|
||||
>t10 : Symbol(t10, Decl(jsxHash.tsx, 8, 3))
|
||||
|
||||
var t11 = <a>#<i/></a>;
|
||||
>t11 : Symbol(t11, Decl(jsxHash.tsx, 9, 3))
|
||||
|
||||
var t12 = <a>#</a>;
|
||||
>t12 : Symbol(t12, Decl(jsxHash.tsx, 10, 3))
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
=== tests/cases/compiler/jsxHash.tsx ===
|
||||
var t02 = <a>{0}#</a>;
|
||||
>t02 : any
|
||||
><a>{0}#</a> : any
|
||||
>a : any
|
||||
>a : any
|
||||
|
||||
var t03 = <a>#{0}</a>;
|
||||
>t03 : any
|
||||
><a>#{0}</a> : any
|
||||
>a : any
|
||||
>a : any
|
||||
|
||||
var t04 = <a>#{0}#</a>;
|
||||
>t04 : any
|
||||
><a>#{0}#</a> : any
|
||||
>a : any
|
||||
>a : any
|
||||
|
||||
var t05 = <a>#<i></i></a>;
|
||||
>t05 : any
|
||||
><a>#<i></i></a> : any
|
||||
>a : any
|
||||
><i></i> : any
|
||||
>i : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t06 = <a>#<i></i></a>;
|
||||
>t06 : any
|
||||
><a>#<i></i></a> : any
|
||||
>a : any
|
||||
><i></i> : any
|
||||
>i : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t07 = <a>#<i>#</i></a>;
|
||||
>t07 : any
|
||||
><a>#<i>#</i></a> : any
|
||||
>a : any
|
||||
><i>#</i> : any
|
||||
>i : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t08 = <a><i></i>#</a>;
|
||||
>t08 : any
|
||||
><a><i></i>#</a> : any
|
||||
>a : any
|
||||
><i></i> : any
|
||||
>i : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t09 = <a>#<i></i>#</a>;
|
||||
>t09 : any
|
||||
><a>#<i></i>#</a> : any
|
||||
>a : any
|
||||
><i></i> : any
|
||||
>i : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t10 = <a><i/>#</a>;
|
||||
>t10 : any
|
||||
><a><i/>#</a> : any
|
||||
>a : any
|
||||
><i/> : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t11 = <a>#<i/></a>;
|
||||
>t11 : any
|
||||
><a>#<i/></a> : any
|
||||
>a : any
|
||||
><i/> : any
|
||||
>i : any
|
||||
>a : any
|
||||
|
||||
var t12 = <a>#</a>;
|
||||
>t12 : any
|
||||
><a>#</a> : any
|
||||
>a : any
|
||||
>a : any
|
||||
|
||||
@@ -62,10 +62,8 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(24,15): error TS1003:
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(25,7): error TS1005: '...' expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(25,7): error TS2304: Cannot find name 'props'.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(27,17): error TS1005: '>' expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(27,18): error TS1109: Expression expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(28,10): error TS2304: Cannot find name 'props'.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(28,28): error TS1005: '>' expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(28,29): error TS1109: Expression expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(32,6): error TS1005: '{' expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(33,6): error TS1005: '{' expected.
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(33,7): error TS1109: Expression expected.
|
||||
@@ -73,7 +71,7 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,4): error TS1003:
|
||||
tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002: Expected corresponding JSX closing tag for 'a'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (73 errors) ====
|
||||
==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (71 errors) ====
|
||||
declare var React: any;
|
||||
|
||||
</>;
|
||||
@@ -229,15 +227,11 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002
|
||||
<div>stuff</div {...props}>;
|
||||
~
|
||||
!!! error TS1005: '>' expected.
|
||||
~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
<div {...props}>stuff</div {...props}>;
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'props'.
|
||||
~
|
||||
!!! error TS1005: '>' expected.
|
||||
~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
|
||||
<a>></a>;
|
||||
<a> ></a>;
|
||||
|
||||
@@ -65,17 +65,17 @@ a['foo'] > ;
|
||||
<a b=>;
|
||||
var x = <div>one</div><div>two</div>;;
|
||||
var x = <div>one</div> /* intervening comment */ /* intervening comment */ <div>two</div>;;
|
||||
<a>{"str"};}</a>;
|
||||
<span className="a"/>, id="b" />;
|
||||
<div className=/>"app">;
|
||||
<a>{"str"}}</a>;
|
||||
<span className="a"/> id="b" />;
|
||||
<div className=/>>;
|
||||
<div {...props}/>;
|
||||
|
||||
<div>stuff</div> {}...props}>;
|
||||
<div {...props}>stuff</div> {}...props}>;
|
||||
<div>stuff</div>...props}>;
|
||||
<div {...props}>stuff</div>...props}>;
|
||||
|
||||
<a>></a>;
|
||||
<a> ></a>;
|
||||
<a b=>;
|
||||
<a b={ < }>;
|
||||
<a>}</a>;
|
||||
<a /> .../*hai*/asdf/>;</></></></>;
|
||||
<a /> /*hai*//*hai*/asdf/>;</></></></>;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(7,30): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'.
|
||||
Type 'number | string' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
|
||||
==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (3 errors) ====
|
||||
==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ====
|
||||
function map<T, U>(xs: T[], f: (x: T) => U) {
|
||||
var ys: U[] = [];
|
||||
xs.forEach(x => ys.push(f(x)));
|
||||
@@ -13,8 +12,6 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e
|
||||
}
|
||||
|
||||
var r0 = map([1, ""], (x) => x.toString());
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
var r5 = map<any, any>([1, ""], (x) => x.toString());
|
||||
var r6 = map<Object, Object>([1, ""], (x) => x.toString());
|
||||
var r7 = map<number, string>([1, ""], (x) => x.toString()); // error
|
||||
|
||||
@@ -42,5 +42,6 @@ var C2 = (function () {
|
||||
return C2;
|
||||
})();
|
||||
var b = {
|
||||
x: function () { }, 1: // error
|
||||
x: function () { }, 1: // error
|
||||
// error
|
||||
};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [paramterDestrcuturingDeclaration.ts]
|
||||
|
||||
interface C {
|
||||
({p: name}): any;
|
||||
new ({p: boolean}): any;
|
||||
}
|
||||
|
||||
|
||||
//// [paramterDestrcuturingDeclaration.js]
|
||||
|
||||
|
||||
//// [paramterDestrcuturingDeclaration.d.ts]
|
||||
interface C {
|
||||
({p: name}: {
|
||||
p: any;
|
||||
}): any;
|
||||
new ({p: boolean}: {
|
||||
p: any;
|
||||
}): any;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/paramterDestrcuturingDeclaration.ts ===
|
||||
|
||||
interface C {
|
||||
>C : Symbol(C, Decl(paramterDestrcuturingDeclaration.ts, 0, 0))
|
||||
|
||||
({p: name}): any;
|
||||
>p : Symbol(p)
|
||||
>name : Symbol(name, Decl(paramterDestrcuturingDeclaration.ts, 2, 6))
|
||||
|
||||
new ({p: boolean}): any;
|
||||
>p : Symbol(p)
|
||||
>boolean : Symbol(boolean, Decl(paramterDestrcuturingDeclaration.ts, 3, 10))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/paramterDestrcuturingDeclaration.ts ===
|
||||
|
||||
interface C {
|
||||
>C : C
|
||||
|
||||
({p: name}): any;
|
||||
>p : any
|
||||
>name : any
|
||||
|
||||
new ({p: boolean}): any;
|
||||
>p : any
|
||||
>boolean : any
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(5,18): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(5,22): error TS1109: Expression expected.
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(5,23): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(6,18): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(6,26): error TS1109: Expression expected.
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts(6,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/RegularExpressions/parseRegularExpressionMixedWithComments.ts (6 errors) ====
|
||||
var regex1 = / asdf /;
|
||||
var regex2 = /**// asdf /;
|
||||
var regex3 = /**///**/ asdf / // should be a comment line
|
||||
1;
|
||||
var regex4 = /**// /**/asdf /;
|
||||
~~~
|
||||
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
~~~~~~~
|
||||
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
var regex5 = /**// asdf/**/ /;
|
||||
~~~~~~~
|
||||
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
~~~
|
||||
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [parseRegularExpressionMixedWithComments.ts]
|
||||
var regex1 = / asdf /;
|
||||
var regex2 = /**// asdf /;
|
||||
var regex3 = /**///**/ asdf / // should be a comment line
|
||||
1;
|
||||
var regex4 = /**// /**/asdf /;
|
||||
var regex5 = /**// asdf/**/ /;
|
||||
|
||||
//// [parseRegularExpressionMixedWithComments.js]
|
||||
var regex1 = / asdf /;
|
||||
var regex2 = / asdf /;
|
||||
var regex3 = 1;
|
||||
var regex4 = / / * * /asdf /;
|
||||
var regex5 = / asdf/ * * / /;
|
||||
@@ -890,7 +890,7 @@ var Formatting;
|
||||
return result;
|
||||
};
|
||||
Indenter.GetIndentSizeFromIndentText = function (indentText, editorOptions) {
|
||||
return GetIndentSizeFromText(indentText, editorOptions, false);
|
||||
return GetIndentSizeFromText(indentText, editorOptions, /*includeNonIndentChars:*/ false);
|
||||
};
|
||||
Indenter.GetIndentSizeFromText = function (text, editorOptions, includeNonIndentChars) {
|
||||
var indentSize = 0;
|
||||
@@ -1174,7 +1174,7 @@ var Formatting;
|
||||
return null;
|
||||
var origIndentText = this.snapshot.GetText(new Span(indentEditInfo.OrigIndentPosition, indentEditInfo.OrigIndentLength()));
|
||||
var newIndentText = indentEditInfo.Indentation();
|
||||
var origIndentSize = Indenter.GetIndentSizeFromText(origIndentText, this.editorOptions, true);
|
||||
var origIndentSize = Indenter.GetIndentSizeFromText(origIndentText, this.editorOptions, /*includeNonIndentChars*/ true);
|
||||
var newIndentSize = Indenter.GetIndentSizeFromIndentText(newIndentText, this.editorOptions);
|
||||
// Check the child's position whether it's before the parent position
|
||||
// if so indent the child based on the first token on the line as opposed to the parent position
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//// [tests/cases/conformance/externalModules/reexportClassDefinition.ts] ////
|
||||
|
||||
//// [foo1.ts]
|
||||
class x{}
|
||||
export = x;
|
||||
|
||||
//// [foo2.ts]
|
||||
import foo1 = require('./foo1');
|
||||
|
||||
export = {
|
||||
x: foo1
|
||||
}
|
||||
|
||||
//// [foo3.ts]
|
||||
import foo2 = require('./foo2')
|
||||
class x extends foo2.x {}
|
||||
|
||||
|
||||
|
||||
//// [foo1.js]
|
||||
var x = (function () {
|
||||
function x() {
|
||||
}
|
||||
return x;
|
||||
})();
|
||||
module.exports = x;
|
||||
//// [foo2.js]
|
||||
var foo1 = require('./foo1');
|
||||
module.exports = {
|
||||
x: foo1
|
||||
};
|
||||
//// [foo3.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var foo2 = require('./foo2');
|
||||
var x = (function (_super) {
|
||||
__extends(x, _super);
|
||||
function x() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
return x;
|
||||
})(foo2.x);
|
||||
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/externalModules/foo3.ts ===
|
||||
import foo2 = require('./foo2')
|
||||
>foo2 : Symbol(foo2, Decl(foo3.ts, 0, 0))
|
||||
|
||||
class x extends foo2.x {}
|
||||
>x : Symbol(x, Decl(foo3.ts, 0, 31))
|
||||
>foo2 : Symbol(foo2, Decl(foo3.ts, 0, 0))
|
||||
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo1.ts ===
|
||||
class x{}
|
||||
>x : Symbol(x, Decl(foo1.ts, 0, 0))
|
||||
|
||||
export = x;
|
||||
>x : Symbol(x, Decl(foo1.ts, 0, 0))
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo2.ts ===
|
||||
import foo1 = require('./foo1');
|
||||
>foo1 : Symbol(foo1, Decl(foo2.ts, 0, 0))
|
||||
|
||||
export = {
|
||||
x: foo1
|
||||
>x : Symbol(x, Decl(foo2.ts, 2, 10))
|
||||
>foo1 : Symbol(foo1, Decl(foo2.ts, 0, 0))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
=== tests/cases/conformance/externalModules/foo3.ts ===
|
||||
import foo2 = require('./foo2')
|
||||
>foo2 : { x: typeof x; }
|
||||
|
||||
class x extends foo2.x {}
|
||||
>x : x
|
||||
>foo2.x : x
|
||||
>foo2 : { x: typeof x; }
|
||||
>x : typeof x
|
||||
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo1.ts ===
|
||||
class x{}
|
||||
>x : x
|
||||
|
||||
export = x;
|
||||
>x : x
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo2.ts ===
|
||||
import foo1 = require('./foo1');
|
||||
>foo1 : typeof foo1
|
||||
|
||||
export = {
|
||||
>{ x: foo1} : { x: typeof foo1; }
|
||||
|
||||
x: foo1
|
||||
>x : typeof foo1
|
||||
>foo1 : typeof foo1
|
||||
}
|
||||
|
||||
@@ -14,19 +14,19 @@ System.register(['file1', 'file2'], function(exports_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters:[
|
||||
function (_file1_1) {
|
||||
file1_1 = _file1_1;
|
||||
exports_1("n", file1_1["default"]);
|
||||
exports_1("n1", file1_1["default"]);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
function (file1_1_1) {
|
||||
file1_1 = file1_1_1;
|
||||
},
|
||||
function (_n2) {
|
||||
n2 = _n2;
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
function (n2_1) {
|
||||
n2 = n2_1;
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n", file1_1["default"]);
|
||||
exports_1("n1", file1_1["default"]);
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,19 +14,19 @@ System.register(['file1', 'file2'], function(exports_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters:[
|
||||
function (_file1_1) {
|
||||
file1_1 = _file1_1;
|
||||
exports_1("n", file1_1.default);
|
||||
exports_1("n1", file1_1.default);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
function (file1_1_1) {
|
||||
file1_1 = file1_1_1;
|
||||
},
|
||||
function (_n2) {
|
||||
n2 = _n2;
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
function (n2_1) {
|
||||
n2 = n2_1;
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
exports_1("n", file1_1.default);
|
||||
exports_1("n1", file1_1.default);
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -59,8 +59,8 @@ System.register(['bar'], function(exports_1) {
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (_bar_1) {
|
||||
exportStar_1(_bar_1);
|
||||
function (bar_1_1) {
|
||||
exportStar_1(bar_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
@@ -82,8 +82,8 @@ System.register(['bar'], function(exports_1) {
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (_bar_1) {
|
||||
exportStar_1(_bar_1);
|
||||
function (bar_1_1) {
|
||||
exportStar_1(bar_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("x", x);
|
||||
@@ -108,14 +108,14 @@ System.register(['a', 'bar'], function(exports_1) {
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (_a_1) {
|
||||
var reexports_1 = {};
|
||||
reexports_1["x"] = _a_1["x"];
|
||||
reexports_1["z"] = _a_1["y"];
|
||||
exports_1(reexports_1);
|
||||
function (a_1_1) {
|
||||
exports_1({
|
||||
"x": a_1_1["x"],
|
||||
"z": a_1_1["y"]
|
||||
});
|
||||
},
|
||||
function (_bar_1) {
|
||||
exportStar_1(_bar_1);
|
||||
function (bar_1_1) {
|
||||
exportStar_1(bar_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
@@ -130,11 +130,11 @@ System.register(['a'], function(exports_1) {
|
||||
exports_1("default", default_1);
|
||||
return {
|
||||
setters:[
|
||||
function (_a_1) {
|
||||
var reexports_1 = {};
|
||||
reexports_1["s"] = _a_1["s"];
|
||||
reexports_1["s2"] = _a_1["s1"];
|
||||
exports_1(reexports_1);
|
||||
function (a_1_1) {
|
||||
exports_1({
|
||||
"s": a_1_1["s"],
|
||||
"s2": a_1_1["s1"]
|
||||
});
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("z", z);
|
||||
@@ -154,8 +154,8 @@ System.register(['a'], function(exports_1) {
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (_a_1) {
|
||||
exportStar_1(_a_1);
|
||||
function (a_1_1) {
|
||||
exportStar_1(a_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/compiler/systemModule14.ts(6,17): error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule14.ts (1 errors) ====
|
||||
|
||||
function foo() {
|
||||
return a;
|
||||
}
|
||||
|
||||
import {a} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
export {foo}
|
||||
|
||||
var x = 1;
|
||||
export {foo as b}
|
||||
@@ -0,0 +1,31 @@
|
||||
//// [systemModule14.ts]
|
||||
|
||||
function foo() {
|
||||
return a;
|
||||
}
|
||||
|
||||
import {a} from "foo";
|
||||
export {foo}
|
||||
|
||||
var x = 1;
|
||||
export {foo as b}
|
||||
|
||||
//// [systemModule14.js]
|
||||
System.register(["foo"], function(exports_1) {
|
||||
var foo_1;
|
||||
var x;
|
||||
function foo() {
|
||||
return foo_1.a;
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (foo_1_1) {
|
||||
foo_1 = foo_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("foo", foo);
|
||||
x = 1;
|
||||
exports_1("b", foo);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
//// [tests/cases/compiler/systemModule15.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
|
||||
|
||||
import * as moduleB from "./file2"
|
||||
|
||||
declare function use(v: any): void;
|
||||
|
||||
use(moduleB.value);
|
||||
use(moduleB.moduleC);
|
||||
use(moduleB.moduleCStar);
|
||||
|
||||
//// [file2.ts]
|
||||
|
||||
import * as moduleCStar from "./file3"
|
||||
import {value2} from "./file4"
|
||||
import moduleC from "./file3"
|
||||
import {value} from "./file3"
|
||||
|
||||
export {
|
||||
moduleCStar,
|
||||
moduleC,
|
||||
value
|
||||
}
|
||||
|
||||
//// [file3.ts]
|
||||
|
||||
export var value = "youpi";
|
||||
export default value;
|
||||
|
||||
//// [file4.ts]
|
||||
|
||||
export var value2 = "v";
|
||||
|
||||
//// [file3.js]
|
||||
System.register([], function(exports_1) {
|
||||
var value;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
exports_1("value", value = "youpi");
|
||||
exports_1("default",value);
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file4.js]
|
||||
System.register([], function(exports_1) {
|
||||
var value2;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
exports_1("value2", value2 = "v");
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file2.js]
|
||||
System.register(["./file3"], function(exports_1) {
|
||||
var moduleCStar, file3_1, file3_2;
|
||||
return {
|
||||
setters:[
|
||||
function (moduleCStar_1) {
|
||||
moduleCStar = moduleCStar_1;
|
||||
file3_1 = moduleCStar_1;
|
||||
file3_2 = moduleCStar_1;
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("moduleCStar", moduleCStar);
|
||||
exports_1("moduleC", file3_1["default"]);
|
||||
exports_1("value", file3_2.value);
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file1.js]
|
||||
System.register(["./file2"], function(exports_1) {
|
||||
var moduleB;
|
||||
return {
|
||||
setters:[
|
||||
function (moduleB_1) {
|
||||
moduleB = moduleB_1;
|
||||
}],
|
||||
execute: function() {
|
||||
use(moduleB.value);
|
||||
use(moduleB.moduleC);
|
||||
use(moduleB.moduleCStar);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
|
||||
import * as moduleB from "./file2"
|
||||
>moduleB : Symbol(moduleB, Decl(file1.ts, 2, 6))
|
||||
|
||||
declare function use(v: any): void;
|
||||
>use : Symbol(use, Decl(file1.ts, 2, 34))
|
||||
>v : Symbol(v, Decl(file1.ts, 4, 21))
|
||||
|
||||
use(moduleB.value);
|
||||
>use : Symbol(use, Decl(file1.ts, 2, 34))
|
||||
>moduleB.value : Symbol(moduleB.value, Decl(file2.ts, 8, 12))
|
||||
>moduleB : Symbol(moduleB, Decl(file1.ts, 2, 6))
|
||||
>value : Symbol(moduleB.value, Decl(file2.ts, 8, 12))
|
||||
|
||||
use(moduleB.moduleC);
|
||||
>use : Symbol(use, Decl(file1.ts, 2, 34))
|
||||
>moduleB.moduleC : Symbol(moduleB.moduleC, Decl(file2.ts, 7, 16))
|
||||
>moduleB : Symbol(moduleB, Decl(file1.ts, 2, 6))
|
||||
>moduleC : Symbol(moduleB.moduleC, Decl(file2.ts, 7, 16))
|
||||
|
||||
use(moduleB.moduleCStar);
|
||||
>use : Symbol(use, Decl(file1.ts, 2, 34))
|
||||
>moduleB.moduleCStar : Symbol(moduleB.moduleCStar, Decl(file2.ts, 6, 8))
|
||||
>moduleB : Symbol(moduleB, Decl(file1.ts, 2, 6))
|
||||
>moduleCStar : Symbol(moduleB.moduleCStar, Decl(file2.ts, 6, 8))
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
|
||||
import * as moduleCStar from "./file3"
|
||||
>moduleCStar : Symbol(moduleCStar, Decl(file2.ts, 1, 6))
|
||||
|
||||
import {value2} from "./file4"
|
||||
>value2 : Symbol(value2, Decl(file2.ts, 2, 8))
|
||||
|
||||
import moduleC from "./file3"
|
||||
>moduleC : Symbol(moduleC, Decl(file2.ts, 3, 6))
|
||||
|
||||
import {value} from "./file3"
|
||||
>value : Symbol(value, Decl(file2.ts, 4, 8))
|
||||
|
||||
export {
|
||||
moduleCStar,
|
||||
>moduleCStar : Symbol(moduleCStar, Decl(file2.ts, 6, 8))
|
||||
|
||||
moduleC,
|
||||
>moduleC : Symbol(moduleC, Decl(file2.ts, 7, 16))
|
||||
|
||||
value
|
||||
>value : Symbol(value, Decl(file2.ts, 8, 12))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/file3.ts ===
|
||||
|
||||
export var value = "youpi";
|
||||
>value : Symbol(value, Decl(file3.ts, 1, 10))
|
||||
|
||||
export default value;
|
||||
>value : Symbol(value, Decl(file3.ts, 1, 10))
|
||||
|
||||
=== tests/cases/compiler/file4.ts ===
|
||||
|
||||
export var value2 = "v";
|
||||
>value2 : Symbol(value2, Decl(file4.ts, 1, 10))
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
|
||||
import * as moduleB from "./file2"
|
||||
>moduleB : typeof moduleB
|
||||
|
||||
declare function use(v: any): void;
|
||||
>use : (v: any) => void
|
||||
>v : any
|
||||
|
||||
use(moduleB.value);
|
||||
>use(moduleB.value) : void
|
||||
>use : (v: any) => void
|
||||
>moduleB.value : string
|
||||
>moduleB : typeof moduleB
|
||||
>value : string
|
||||
|
||||
use(moduleB.moduleC);
|
||||
>use(moduleB.moduleC) : void
|
||||
>use : (v: any) => void
|
||||
>moduleB.moduleC : string
|
||||
>moduleB : typeof moduleB
|
||||
>moduleC : string
|
||||
|
||||
use(moduleB.moduleCStar);
|
||||
>use(moduleB.moduleCStar) : void
|
||||
>use : (v: any) => void
|
||||
>moduleB.moduleCStar : typeof
|
||||
>moduleB : typeof moduleB
|
||||
>moduleCStar : typeof
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
|
||||
import * as moduleCStar from "./file3"
|
||||
>moduleCStar : typeof moduleCStar
|
||||
|
||||
import {value2} from "./file4"
|
||||
>value2 : string
|
||||
|
||||
import moduleC from "./file3"
|
||||
>moduleC : string
|
||||
|
||||
import {value} from "./file3"
|
||||
>value : string
|
||||
|
||||
export {
|
||||
moduleCStar,
|
||||
>moduleCStar : typeof moduleCStar
|
||||
|
||||
moduleC,
|
||||
>moduleC : string
|
||||
|
||||
value
|
||||
>value : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/file3.ts ===
|
||||
|
||||
export var value = "youpi";
|
||||
>value : string
|
||||
>"youpi" : string
|
||||
|
||||
export default value;
|
||||
>value : string
|
||||
|
||||
=== tests/cases/compiler/file4.ts ===
|
||||
|
||||
export var value2 = "v";
|
||||
>value2 : string
|
||||
>"v" : string
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
tests/cases/compiler/systemModule16.ts(2,20): error TS2307: Cannot find module 'foo'.
|
||||
tests/cases/compiler/systemModule16.ts(3,20): error TS2307: Cannot find module 'bar'.
|
||||
tests/cases/compiler/systemModule16.ts(4,15): error TS2307: Cannot find module 'foo'.
|
||||
tests/cases/compiler/systemModule16.ts(5,15): error TS2307: Cannot find module 'bar'.
|
||||
tests/cases/compiler/systemModule16.ts(8,32): error TS2307: Cannot find module 'foo'.
|
||||
tests/cases/compiler/systemModule16.ts(9,32): error TS2307: Cannot find module 'bar'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule16.ts (6 errors) ====
|
||||
|
||||
import * as x from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
import * as y from "bar";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'bar'.
|
||||
export * from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
export * from "bar"
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'bar'.
|
||||
export {x}
|
||||
export {y}
|
||||
import {a1, b1, c1 as d1} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
export {a2, b2, c2 as d2} from "bar";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'bar'.
|
||||
|
||||
x,y,a1,b1,d1;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//// [systemModule16.ts]
|
||||
|
||||
import * as x from "foo";
|
||||
import * as y from "bar";
|
||||
export * from "foo";
|
||||
export * from "bar"
|
||||
export {x}
|
||||
export {y}
|
||||
import {a1, b1, c1 as d1} from "foo";
|
||||
export {a2, b2, c2 as d2} from "bar";
|
||||
|
||||
x,y,a1,b1,d1;
|
||||
|
||||
|
||||
//// [systemModule16.js]
|
||||
System.register(["foo", "bar"], function(exports_1) {
|
||||
var x, y, foo_1;
|
||||
var exportedNames_1 = {
|
||||
'x': true,
|
||||
'y': true,
|
||||
'a2': true,
|
||||
'b2': true,
|
||||
'd2': true
|
||||
};
|
||||
function exportStar_1(m) {
|
||||
var exports = {};
|
||||
for(var n in m) {
|
||||
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
|
||||
}
|
||||
exports_1(exports);
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (x_1) {
|
||||
x = x_1;
|
||||
exportStar_1(x_1);
|
||||
foo_1 = x_1;
|
||||
},
|
||||
function (y_1) {
|
||||
y = y_1;
|
||||
exportStar_1(y_1);
|
||||
exports_1({
|
||||
"a2": y_1["a2"],
|
||||
"b2": y_1["b2"],
|
||||
"d2": y_1["c2"]
|
||||
});
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("x", x);
|
||||
exports_1("y", y);
|
||||
x, y, foo_1.a1, foo_1.b1, foo_1.c1;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -38,24 +38,24 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'],
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (_ns) {
|
||||
ns = _ns;
|
||||
function (ns_1) {
|
||||
ns = ns_1;
|
||||
},
|
||||
function (_file2_1) {
|
||||
file2_1 = _file2_1;
|
||||
function (file2_1_1) {
|
||||
file2_1 = file2_1_1;
|
||||
},
|
||||
function (_file3_1) {
|
||||
file3_1 = _file3_1;
|
||||
function (file3_1_1) {
|
||||
file3_1 = file3_1_1;
|
||||
},
|
||||
function (_) {},
|
||||
function (_file5_1) {
|
||||
file5_1 = _file5_1;
|
||||
function (_1) {},
|
||||
function (file5_1_1) {
|
||||
file5_1 = file5_1_1;
|
||||
},
|
||||
function (_ns3) {
|
||||
ns3 = _ns3;
|
||||
function (ns3_1) {
|
||||
ns3 = ns3_1;
|
||||
},
|
||||
function (_file7_1) {
|
||||
exportStar_1(_file7_1);
|
||||
function (file7_1_1) {
|
||||
exportStar_1(file7_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
ns.f();
|
||||
|
||||
@@ -38,8 +38,8 @@ System.register(['./foo'], function(exports_1) {
|
||||
var Bar;
|
||||
return {
|
||||
setters:[
|
||||
function (_foo_1) {
|
||||
foo_1 = _foo_1;
|
||||
function (foo_1_1) {
|
||||
foo_1 = foo_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
Bar = (function (_super) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
tests/cases/conformance/jsx/tsxErrorRecovery1.tsx(5,19): error TS1109: Expression expected.
|
||||
tests/cases/conformance/jsx/tsxErrorRecovery1.tsx(8,11): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/conformance/jsx/tsxErrorRecovery1.tsx(8,12): error TS1005: '}' expected.
|
||||
tests/cases/conformance/jsx/tsxErrorRecovery1.tsx(9,1): error TS17002: Expected corresponding JSX closing tag for 'div'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/tsxErrorRecovery1.tsx (1 errors) ====
|
||||
==== tests/cases/conformance/jsx/tsxErrorRecovery1.tsx (4 errors) ====
|
||||
|
||||
declare namespace JSX { interface Element { } }
|
||||
|
||||
@@ -12,4 +15,10 @@ tests/cases/conformance/jsx/tsxErrorRecovery1.tsx(5,19): error TS1109: Expressio
|
||||
}
|
||||
// Shouldn't see any errors down here
|
||||
var y = { a: 1 };
|
||||
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS1005: '}' expected.
|
||||
|
||||
|
||||
!!! error TS17002: Expected corresponding JSX closing tag for 'div'.
|
||||
@@ -11,7 +11,9 @@ var y = { a: 1 };
|
||||
|
||||
//// [tsxErrorRecovery1.jsx]
|
||||
function foo() {
|
||||
var x = <div> {} </div>;
|
||||
var x = <div> {}div>
|
||||
}
|
||||
// Shouldn't see any errors down here
|
||||
var y = {a} 1 };
|
||||
</>;
|
||||
}
|
||||
// Shouldn't see any errors down here
|
||||
var y = { a: 1 };
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [typeAliasDeclarationEmit.ts]
|
||||
|
||||
export type callback<T> = () => T;
|
||||
|
||||
export type CallbackArray<T extends callback> = () => T;
|
||||
|
||||
//// [typeAliasDeclarationEmit.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
});
|
||||
|
||||
|
||||
//// [typeAliasDeclarationEmit.d.ts]
|
||||
export declare type callback<T> = () => T;
|
||||
export declare type CallbackArray<T extends callback> = () => T;
|
||||
@@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
|
||||
|
||||
export type callback<T> = () => T;
|
||||
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
|
||||
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
|
||||
|
||||
export type CallbackArray<T extends callback> = () => T;
|
||||
>CallbackArray : Symbol(CallbackArray, Decl(typeAliasDeclarationEmit.ts, 1, 34))
|
||||
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))
|
||||
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
|
||||
|
||||
export type callback<T> = () => T;
|
||||
>callback : () => T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
export type CallbackArray<T extends callback> = () => T;
|
||||
>CallbackArray : () => T
|
||||
>T : T
|
||||
>callback : () => T
|
||||
>T : T
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [typeAliasDeclarationEmit2.ts]
|
||||
|
||||
export type A<a> = { value: a };
|
||||
|
||||
//// [typeAliasDeclarationEmit2.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
});
|
||||
|
||||
|
||||
//// [typeAliasDeclarationEmit2.d.ts]
|
||||
export declare type A<a> = {
|
||||
value: a;
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
|
||||
|
||||
export type A<a> = { value: a };
|
||||
>A : Symbol(A, Decl(typeAliasDeclarationEmit2.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))
|
||||
>value : Symbol(value, Decl(typeAliasDeclarationEmit2.ts, 1, 20))
|
||||
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
|
||||
|
||||
export type A<a> = { value: a };
|
||||
>A : { value: a; }
|
||||
>a : a
|
||||
>value : a
|
||||
>a : a
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts(93,22): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts (1 errors) ====
|
||||
// In the true expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when true,
|
||||
// provided the true expression contains no assignments to the variable or parameter.
|
||||
// In the false expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
|
||||
// provided the false expression contains no assignments to the variable or parameter.
|
||||
|
||||
function foo(x: number | string) {
|
||||
return typeof x === "string"
|
||||
? x.length // string
|
||||
: x++; // number
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x)// string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
// x is assigned in the if false branch, the type is not narrowed
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
? (x = "Hello" && x) // string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
? x // string | number
|
||||
: (x = 10 && x); // string | number
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
return typeof x === "string"
|
||||
? x // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
// Modify in both branches
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x) // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
return typeof x === "string"
|
||||
? x === "hello" // string
|
||||
: typeof x === "boolean"
|
||||
? x // boolean
|
||||
: x == 10; // number
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
var b: number | boolean;
|
||||
return typeof x === "string"
|
||||
? x === "hello"
|
||||
: ((b = x) && // number | boolean
|
||||
(typeof x === "boolean"
|
||||
? x // boolean
|
||||
: x == 10)); // number
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
var y = 10;
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
return typeof x === "string"
|
||||
? ((y = x.length) && x === "hello") // string
|
||||
: x === 10; // number
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
// Mixing typeguards
|
||||
var b: boolean | number;
|
||||
return typeof x === "string"
|
||||
? x // string
|
||||
: ((b = x) // x is number | boolean
|
||||
&& typeof x === "number"
|
||||
&& x.toString()); // x is number
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
var b: number | boolean | string;
|
||||
return typeof x === "string"
|
||||
? x // number | boolean | string - changed in the false branch
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
&& typeof x === "number"
|
||||
&& (x = 10) // assignment to x
|
||||
&& x); // x is number | boolean | string
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
var b: number | boolean | string;
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
&& typeof x === "number"
|
||||
&& x); // x is number
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts ===
|
||||
// In the true expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when true,
|
||||
// provided the true expression contains no assignments to the variable or parameter.
|
||||
// In the false expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
|
||||
// provided the false expression contains no assignments to the variable or parameter.
|
||||
|
||||
function foo(x: number | string) {
|
||||
>foo : Symbol(foo, Decl(typeGuardsInConditionalExpression.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
|
||||
|
||||
? x.length // string
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
|
||||
: x++; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : Symbol(foo2, Decl(typeGuardsInConditionalExpression.ts, 11, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
|
||||
|
||||
? (x = 10 && x)// string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
|
||||
|
||||
: x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : Symbol(foo3, Decl(typeGuardsInConditionalExpression.ts, 17, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
|
||||
|
||||
// x is assigned in the if false branch, the type is not narrowed
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
|
||||
|
||||
? (x = "Hello" && x) // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
|
||||
|
||||
: x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
>foo4 : Symbol(foo4, Decl(typeGuardsInConditionalExpression.ts, 24, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
|
||||
|
||||
? x // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
|
||||
|
||||
: (x = 10 && x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
>foo5 : Symbol(foo5, Decl(typeGuardsInConditionalExpression.ts, 31, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
|
||||
|
||||
? x // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
|
||||
|
||||
: (x = "hello" && x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
>foo6 : Symbol(foo6, Decl(typeGuardsInConditionalExpression.ts, 37, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
|
||||
// Modify in both branches
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
|
||||
? (x = 10 && x) // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
|
||||
: (x = "hello" && x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : Symbol(foo7, Decl(typeGuardsInConditionalExpression.ts, 43, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
|
||||
? x === "hello" // string
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
|
||||
: typeof x === "boolean"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
|
||||
? x // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
|
||||
: x == 10; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
>foo8 : Symbol(foo8, Decl(typeGuardsInConditionalExpression.ts, 50, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
var b: number | boolean;
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
? x === "hello"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
: ((b = x) && // number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
(typeof x === "boolean"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
? x // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
|
||||
: x == 10)); // number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
>foo9 : Symbol(foo9, Decl(typeGuardsInConditionalExpression.ts, 59, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
|
||||
|
||||
var y = 10;
|
||||
>y : Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7))
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
|
||||
|
||||
? ((y = x.length) && x === "hello") // string
|
||||
>y : Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
|
||||
|
||||
: x === 10; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
>foo10 : Symbol(foo10, Decl(typeGuardsInConditionalExpression.ts, 66, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
|
||||
// Mixing typeguards
|
||||
var b: boolean | number;
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
|
||||
? x // string
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
|
||||
: ((b = x) // x is number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
|
||||
&& typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
|
||||
&& x.toString()); // x is number
|
||||
>x.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
|
||||
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
>foo11 : Symbol(foo11, Decl(typeGuardsInConditionalExpression.ts, 75, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
// Mixing typeguards
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
var b: number | boolean | string;
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
? x // number | boolean | string - changed in the false branch
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
&& typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
&& (x = 10) // assignment to x
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
|
||||
&& x); // x is number | boolean | string
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
>foo12 : Symbol(foo12, Decl(typeGuardsInConditionalExpression.ts, 86, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
|
||||
// Mixing typeguards
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
var b: number | boolean | string;
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7))
|
||||
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
|
||||
? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
>x.toString().length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
>b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
|
||||
&& typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
|
||||
&& x); // x is number
|
||||
>x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts ===
|
||||
// In the true expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when true,
|
||||
// provided the true expression contains no assignments to the variable or parameter.
|
||||
// In the false expression of a conditional expression,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
|
||||
// provided the false expression contains no assignments to the variable or parameter.
|
||||
|
||||
function foo(x: number | string) {
|
||||
>foo : (x: number | string) => number
|
||||
>x : number | string
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x.length // string : x++ : number
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? x.length // string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
: x++; // number
|
||||
>x++ : number
|
||||
>x : number
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? (x = 10 && x)// string | number : x : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? (x = 10 && x)// string | number
|
||||
>(x = 10 && x) : number | string
|
||||
>x = 10 && x : number | string
|
||||
>x : number | string
|
||||
>10 && x : number | string
|
||||
>10 : number
|
||||
>x : number | string
|
||||
|
||||
: x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// x is assigned in the if false branch, the type is not narrowed
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? (x = "Hello" && x) // string | number : x : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? (x = "Hello" && x) // string | number
|
||||
>(x = "Hello" && x) : number | string
|
||||
>x = "Hello" && x : number | string
|
||||
>x : number | string
|
||||
>"Hello" && x : number | string
|
||||
>"Hello" : string
|
||||
>x : number | string
|
||||
|
||||
: x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
>foo4 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x // string | number : (x = 10 && x) : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? x // string | number
|
||||
>x : number | string
|
||||
|
||||
: (x = 10 && x); // string | number
|
||||
>(x = 10 && x) : number | string
|
||||
>x = 10 && x : number | string
|
||||
>x : number | string
|
||||
>10 && x : number | string
|
||||
>10 : number
|
||||
>x : number | string
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
>foo5 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x // string | number : (x = "hello" && x) : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? x // string | number
|
||||
>x : number | string
|
||||
|
||||
: (x = "hello" && x); // string | number
|
||||
>(x = "hello" && x) : number | string
|
||||
>x = "hello" && x : number | string
|
||||
>x : number | string
|
||||
>"hello" && x : number | string
|
||||
>"hello" : string
|
||||
>x : number | string
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
>foo6 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// Modify in both branches
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? (x = 10 && x) // string | number : (x = "hello" && x) : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? (x = 10 && x) // string | number
|
||||
>(x = 10 && x) : number | string
|
||||
>x = 10 && x : number | string
|
||||
>x : number | string
|
||||
>10 && x : number | string
|
||||
>10 : number
|
||||
>x : number | string
|
||||
|
||||
: (x = "hello" && x); // string | number
|
||||
>(x = "hello" && x) : number | string
|
||||
>x = "hello" && x : number | string
|
||||
>x : number | string
|
||||
>"hello" && x : number | string
|
||||
>"hello" : string
|
||||
>x : number | string
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x === "hello" // string : typeof x === "boolean" ? x // boolean : x == 10 : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
? x === "hello" // string
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
|
||||
: typeof x === "boolean"
|
||||
>typeof x === "boolean" ? x // boolean : x == 10 : boolean
|
||||
>typeof x === "boolean" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"boolean" : string
|
||||
|
||||
? x // boolean
|
||||
>x : boolean
|
||||
|
||||
: x == 10; // number
|
||||
>x == 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
>foo8 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
var b: number | boolean;
|
||||
>b : number | boolean
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x === "hello" : ((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
? x === "hello"
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
|
||||
: ((b = x) && // number | boolean
|
||||
>((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
|
||||
>(b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10) : boolean
|
||||
>(b = x) : number | boolean
|
||||
>b = x : number | boolean
|
||||
>b : number | boolean
|
||||
>x : number | boolean
|
||||
|
||||
(typeof x === "boolean"
|
||||
>(typeof x === "boolean" ? x // boolean : x == 10) : boolean
|
||||
>typeof x === "boolean" ? x // boolean : x == 10 : boolean
|
||||
>typeof x === "boolean" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"boolean" : string
|
||||
|
||||
? x // boolean
|
||||
>x : boolean
|
||||
|
||||
: x == 10)); // number
|
||||
>x == 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
>foo9 : (x: number | string) => boolean
|
||||
>x : number | string
|
||||
|
||||
var y = 10;
|
||||
>y : number
|
||||
>10 : number
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? ((y = x.length) && x === "hello") // string : x === 10 : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
? ((y = x.length) && x === "hello") // string
|
||||
>((y = x.length) && x === "hello") : boolean
|
||||
>(y = x.length) && x === "hello" : boolean
|
||||
>(y = x.length) : number
|
||||
>y = x.length : number
|
||||
>y : number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
|
||||
: x === 10; // number
|
||||
>x === 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
>foo10 : (x: number | string | boolean) => string
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguards
|
||||
var b: boolean | number;
|
||||
>b : boolean | number
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
? x // string
|
||||
>x : string
|
||||
|
||||
: ((b = x) // x is number | boolean
|
||||
>((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
|
||||
>(b = x) // x is number | boolean && typeof x === "number" && x.toString() : string
|
||||
>(b = x) // x is number | boolean && typeof x === "number" : boolean
|
||||
>(b = x) : number | boolean
|
||||
>b = x : number | boolean
|
||||
>b : boolean | number
|
||||
>x : number | boolean
|
||||
|
||||
&& typeof x === "number"
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
&& x.toString()); // x is number
|
||||
>x.toString() : string
|
||||
>x.toString : (radix?: number) => string
|
||||
>x : number
|
||||
>toString : (radix?: number) => string
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
>foo11 : (x: number | string | boolean) => number | string | boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguards
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
var b: number | boolean | string;
|
||||
>b : number | boolean | string
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? x // number | boolean | string - changed in the false branch : ((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : number | string | boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
? x // number | boolean | string - changed in the false branch
|
||||
>x : number | string | boolean
|
||||
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
>((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : number | string | boolean
|
||||
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x : number | string | boolean
|
||||
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) : number
|
||||
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" : boolean
|
||||
>(b = x) : number | string | boolean
|
||||
>b = x : number | string | boolean
|
||||
>b : number | boolean | string
|
||||
>x : number | string | boolean
|
||||
|
||||
&& typeof x === "number"
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
&& (x = 10) // assignment to x
|
||||
>(x = 10) : number
|
||||
>x = 10 : number
|
||||
>x : number | string | boolean
|
||||
>10 : number
|
||||
|
||||
&& x); // x is number | boolean | string
|
||||
>x : number | string | boolean
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
>foo12 : (x: number | string | boolean) => number
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguards
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
var b: number | boolean | string;
|
||||
>b : number | boolean | string
|
||||
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here : ((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
>(x = 10 && x.toString().length) : number
|
||||
>x = 10 && x.toString().length : number
|
||||
>x : number | string | boolean
|
||||
>10 && x.toString().length : number
|
||||
>10 : number
|
||||
>x.toString().length : number
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
>length : number
|
||||
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
>((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
|
||||
>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x : number
|
||||
>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" : boolean
|
||||
>(b = x) : number | string | boolean
|
||||
>b = x : number | string | boolean
|
||||
>b : number | boolean | string
|
||||
>x : number | string | boolean
|
||||
|
||||
&& typeof x === "number"
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
&& x); // x is number
|
||||
>x : number
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(127,23): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(131,22): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,16): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (3 errors) ====
|
||||
// In the true branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when true,
|
||||
// provided the true branch statement contains no assignments to the variable or parameter.
|
||||
// In the false branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when false,
|
||||
// provided the false branch statement contains no assignments to the variable or parameter
|
||||
function foo(x: number | string) {
|
||||
if (typeof x === "string") {
|
||||
return x.length; // string
|
||||
}
|
||||
else {
|
||||
return x++; // number
|
||||
}
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
x = 10;
|
||||
return x; // string | number
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
}
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
x = "Hello"; // even though assigned using same type as narrowed expression
|
||||
return x; // string | number
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
}
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
return x; // string | number
|
||||
}
|
||||
else {
|
||||
x = 10; // even though assigned number - this should result in x to be string | number
|
||||
return x; // string | number
|
||||
}
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
return x; // string | number
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
return x; // string | number
|
||||
}
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
// Modify in both branches
|
||||
if (typeof x === "string") {
|
||||
x = 10;
|
||||
return x; // string | number
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
return x; // string | number
|
||||
}
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
if (typeof x === "string") {
|
||||
return x === "hello"; // string
|
||||
}
|
||||
else if (typeof x === "boolean") {
|
||||
return x; // boolean
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
}
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
if (typeof x === "string") {
|
||||
return x === "hello"; // string
|
||||
}
|
||||
else {
|
||||
var b: number | boolean = x; // number | boolean
|
||||
if (typeof x === "boolean") {
|
||||
return x; // boolean
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
}
|
||||
}
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
var y = 10;
|
||||
if (typeof x === "string") {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
y = x.length;
|
||||
return x === "hello"; // string
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
}
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
if (typeof x === "string") {
|
||||
return x === "hello"; // string
|
||||
}
|
||||
else {
|
||||
var y: boolean | string;
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "number"
|
||||
? x === 10 // number
|
||||
: x; // x should be boolean
|
||||
}
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
if (typeof x === "string") {
|
||||
return x; // string | number | boolean - x changed in else branch
|
||||
}
|
||||
else {
|
||||
var y: number| boolean | string;
|
||||
var b = x; // number | boolean | string - because below we are changing value of x in if statement
|
||||
return typeof x === "number"
|
||||
? (
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
)
|
||||
: (
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
);
|
||||
}
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
if (typeof x === "string") {
|
||||
return x.toString(); // string | number | boolean - x changed in else branch
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
}
|
||||
else {
|
||||
x = 10;
|
||||
var b = x; // number | boolean | string
|
||||
return typeof x === "number"
|
||||
? x.toString() // number
|
||||
: x.toString(); // boolean | string
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts ===
|
||||
// In the true branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when true,
|
||||
// provided the true branch statement contains no assignments to the variable or parameter.
|
||||
// In the false branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when false,
|
||||
// provided the false branch statement contains no assignments to the variable or parameter
|
||||
function foo(x: number | string) {
|
||||
>foo : Symbol(foo, Decl(typeGuardsInIfStatement.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13))
|
||||
|
||||
return x.length; // string
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
}
|
||||
else {
|
||||
return x++; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13))
|
||||
}
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : Symbol(foo2, Decl(typeGuardsInIfStatement.ts, 13, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14))
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14))
|
||||
|
||||
x = 10;
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14))
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14))
|
||||
}
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : Symbol(foo3, Decl(typeGuardsInIfStatement.ts, 23, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14))
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14))
|
||||
|
||||
x = "Hello"; // even though assigned using same type as narrowed expression
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14))
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14))
|
||||
}
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
>foo4 : Symbol(foo4, Decl(typeGuardsInIfStatement.ts, 33, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14))
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14))
|
||||
}
|
||||
else {
|
||||
x = 10; // even though assigned number - this should result in x to be string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14))
|
||||
}
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
>foo5 : Symbol(foo5, Decl(typeGuardsInIfStatement.ts, 43, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14))
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14))
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14))
|
||||
}
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
>foo6 : Symbol(foo6, Decl(typeGuardsInIfStatement.ts, 53, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
|
||||
// Modify in both branches
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
|
||||
x = 10;
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
|
||||
return x; // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14))
|
||||
}
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : Symbol(foo7, Decl(typeGuardsInIfStatement.ts, 64, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
|
||||
return x === "hello"; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
}
|
||||
else if (typeof x === "boolean") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
|
||||
return x; // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14))
|
||||
}
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
>foo8 : Symbol(foo8, Decl(typeGuardsInIfStatement.ts, 75, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
|
||||
return x === "hello"; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
}
|
||||
else {
|
||||
var b: number | boolean = x; // number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 81, 11))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
|
||||
if (typeof x === "boolean") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
|
||||
return x; // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14))
|
||||
}
|
||||
}
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
>foo9 : Symbol(foo9, Decl(typeGuardsInIfStatement.ts, 89, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14))
|
||||
|
||||
var y = 10;
|
||||
>y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 91, 7))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14))
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
y = x.length;
|
||||
>y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 91, 7))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
|
||||
return x === "hello"; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14))
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14))
|
||||
}
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
>foo10 : Symbol(foo10, Decl(typeGuardsInIfStatement.ts, 100, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
|
||||
return x === "hello"; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
}
|
||||
else {
|
||||
var y: boolean | string;
|
||||
>y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 107, 11))
|
||||
|
||||
var b = x; // number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 108, 11))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
|
||||
return typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
|
||||
? x === 10 // number
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
|
||||
: x; // x should be boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15))
|
||||
}
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
>foo11 : Symbol(foo11, Decl(typeGuardsInIfStatement.ts, 113, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
|
||||
return x; // string | number | boolean - x changed in else branch
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
}
|
||||
else {
|
||||
var y: number| boolean | string;
|
||||
>y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 121, 11))
|
||||
|
||||
var b = x; // number | boolean | string - because below we are changing value of x in if statement
|
||||
>b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 122, 11))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
|
||||
return typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
|
||||
? (
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
|
||||
)
|
||||
: (
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
>y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 121, 11))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
>foo12 : Symbol(foo12, Decl(typeGuardsInIfStatement.ts, 133, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
|
||||
return x.toString(); // string | number | boolean - x changed in else branch
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
}
|
||||
else {
|
||||
x = 10;
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
|
||||
var b = x; // number | boolean | string
|
||||
>b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 142, 11))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
|
||||
return typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
|
||||
? x.toString() // number
|
||||
>x.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||
|
||||
: x.toString(); // boolean | string
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts ===
|
||||
// In the true branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when true,
|
||||
// provided the true branch statement contains no assignments to the variable or parameter.
|
||||
// In the false branch statement of an �if� statement,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the �if� condition when false,
|
||||
// provided the false branch statement contains no assignments to the variable or parameter
|
||||
function foo(x: number | string) {
|
||||
>foo : (x: number | string) => number
|
||||
>x : number | string
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
return x.length; // string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
else {
|
||||
return x++; // number
|
||||
>x++ : number
|
||||
>x : number
|
||||
}
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
x = 10;
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
x = "Hello"; // even though assigned using same type as narrowed expression
|
||||
>x = "Hello" : string
|
||||
>x : number | string
|
||||
>"Hello" : string
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
else {
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
}
|
||||
function foo4(x: number | string) {
|
||||
>foo4 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
else {
|
||||
x = 10; // even though assigned number - this should result in x to be string | number
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
}
|
||||
function foo5(x: number | string) {
|
||||
>foo5 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// false branch updates the variable - so here it is not number
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
>x = "hello" : string
|
||||
>x : number | string
|
||||
>"hello" : string
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
}
|
||||
function foo6(x: number | string) {
|
||||
>foo6 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// Modify in both branches
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
x = 10;
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
else {
|
||||
x = "hello";
|
||||
>x = "hello" : string
|
||||
>x : number | string
|
||||
>"hello" : string
|
||||
|
||||
return x; // string | number
|
||||
>x : number | string
|
||||
}
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
return x === "hello"; // string
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
}
|
||||
else if (typeof x === "boolean") {
|
||||
>typeof x === "boolean" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"boolean" : string
|
||||
|
||||
return x; // boolean
|
||||
>x : boolean
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x == 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
}
|
||||
function foo8(x: number | string | boolean) {
|
||||
>foo8 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
return x === "hello"; // string
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
}
|
||||
else {
|
||||
var b: number | boolean = x; // number | boolean
|
||||
>b : number | boolean
|
||||
>x : number | boolean
|
||||
|
||||
if (typeof x === "boolean") {
|
||||
>typeof x === "boolean" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"boolean" : string
|
||||
|
||||
return x; // boolean
|
||||
>x : boolean
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x == 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
}
|
||||
}
|
||||
function foo9(x: number | string) {
|
||||
>foo9 : (x: number | string) => boolean
|
||||
>x : number | string
|
||||
|
||||
var y = 10;
|
||||
>y : number
|
||||
>10 : number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
y = x.length;
|
||||
>y = x.length : number
|
||||
>y : number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
return x === "hello"; // string
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
}
|
||||
else {
|
||||
return x == 10; // number
|
||||
>x == 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
}
|
||||
function foo10(x: number | string | boolean) {
|
||||
>foo10 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
return x === "hello"; // string
|
||||
>x === "hello" : boolean
|
||||
>x : string
|
||||
>"hello" : string
|
||||
}
|
||||
else {
|
||||
var y: boolean | string;
|
||||
>y : boolean | string
|
||||
|
||||
var b = x; // number | boolean
|
||||
>b : number | boolean
|
||||
>x : number | boolean
|
||||
|
||||
return typeof x === "number"
|
||||
>typeof x === "number" ? x === 10 // number : x : boolean
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
? x === 10 // number
|
||||
>x === 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
|
||||
: x; // x should be boolean
|
||||
>x : boolean
|
||||
}
|
||||
}
|
||||
function foo11(x: number | string | boolean) {
|
||||
>foo11 : (x: number | string | boolean) => number | string | boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
return x; // string | number | boolean - x changed in else branch
|
||||
>x : number | string | boolean
|
||||
}
|
||||
else {
|
||||
var y: number| boolean | string;
|
||||
>y : number | boolean | string
|
||||
|
||||
var b = x; // number | boolean | string - because below we are changing value of x in if statement
|
||||
>b : number | string | boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
return typeof x === "number"
|
||||
>typeof x === "number" ? ( // change value of x x = 10 && x.toString() // number | boolean | string ) : ( // do not change value y = x && x.toString() // number | boolean | string ) : string
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
? (
|
||||
>( // change value of x x = 10 && x.toString() // number | boolean | string ) : string
|
||||
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
>x = 10 && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>10 && x.toString() : string
|
||||
>10 : number
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
|
||||
)
|
||||
: (
|
||||
>( // do not change value y = x && x.toString() // number | boolean | string ) : string
|
||||
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
>y = x && x.toString() : string
|
||||
>y : number | boolean | string
|
||||
>x && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
function foo12(x: number | string | boolean) {
|
||||
>foo12 : (x: number | string | boolean) => string
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
return x.toString(); // string | number | boolean - x changed in else branch
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
}
|
||||
else {
|
||||
x = 10;
|
||||
>x = 10 : number
|
||||
>x : number | string | boolean
|
||||
>10 : number
|
||||
|
||||
var b = x; // number | boolean | string
|
||||
>b : number | string | boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
return typeof x === "number"
|
||||
>typeof x === "number" ? x.toString() // number : x.toString() : string
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
? x.toString() // number
|
||||
>x.toString() : string
|
||||
>x.toString : (radix?: number) => string
|
||||
>x : number
|
||||
>toString : (radix?: number) => string
|
||||
|
||||
: x.toString(); // boolean | string
|
||||
>x.toString() : string
|
||||
>x.toString : () => string
|
||||
>x : string | boolean
|
||||
>toString : () => string
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts(43,22): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts(45,21): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts (2 errors) ====
|
||||
// In the right operand of a && operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when true,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
return typeof x === "string" && x.length === 10; // string
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
// modify x in right hand operand
|
||||
return typeof x === "string" && ((x = 10) && x); // string | number
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x === "string" && ((x = "hello") && x); // string | number
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& typeof x !== "number" // number | boolean
|
||||
&& x; // boolean
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
&& x)); // boolean
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10) // number
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
var y: number| boolean | string;
|
||||
var z: number| boolean | string;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x !== "string"
|
||||
&& ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
&& (typeof x === "number"
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x !== "string"
|
||||
&& (x = 10) // change x - number| string
|
||||
&& (typeof x === "number"
|
||||
? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts ===
|
||||
// In the right operand of a && operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when true,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
>foo : Symbol(foo, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13))
|
||||
|
||||
return typeof x === "string" && x.length === 10; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : Symbol(foo2, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 5, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14))
|
||||
|
||||
// modify x in right hand operand
|
||||
return typeof x === "string" && ((x = 10) && x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14))
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : Symbol(foo3, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 9, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14))
|
||||
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x === "string" && ((x = "hello") && x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14))
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
>foo4 : Symbol(foo4, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 13, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14))
|
||||
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14))
|
||||
|
||||
&& typeof x !== "number" // number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14))
|
||||
|
||||
&& x; // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14))
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : Symbol(foo5, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 18, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14))
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
>b : Symbol(b, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 21, 7))
|
||||
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14))
|
||||
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 21, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14))
|
||||
|
||||
&& x)); // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14))
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
>foo6 : Symbol(foo6, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 25, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14))
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14))
|
||||
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14))
|
||||
|
||||
? x // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14))
|
||||
|
||||
: x === 10) // number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14))
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : Symbol(foo7, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 32, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
|
||||
var y: number| boolean | string;
|
||||
>y : Symbol(y, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 34, 7))
|
||||
|
||||
var z: number| boolean | string;
|
||||
>z : Symbol(z, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 35, 7))
|
||||
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x !== "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
|
||||
&& ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
>z : Symbol(z, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 35, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
|
||||
&& (typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
>y : Symbol(y, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 34, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
>foo8 : Symbol(foo8, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 45, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x !== "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
|
||||
&& (x = 10) // change x - number| string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
|
||||
&& (typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
|
||||
? x // number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
|
||||
: x.length); // string
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts ===
|
||||
// In the right operand of a && operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when true,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
>foo : (x: number | string) => boolean
|
||||
>x : number | string
|
||||
|
||||
return typeof x === "string" && x.length === 10; // string
|
||||
>typeof x === "string" && x.length === 10 : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>x.length === 10 : boolean
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
>10 : number
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// modify x in right hand operand
|
||||
return typeof x === "string" && ((x = 10) && x); // string | number
|
||||
>typeof x === "string" && ((x = 10) && x) : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>((x = 10) && x) : number | string
|
||||
>(x = 10) && x : number | string
|
||||
>(x = 10) : number
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
>x : number | string
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : (x: number | string) => number | string
|
||||
>x : number | string
|
||||
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x === "string" && ((x = "hello") && x); // string | number
|
||||
>typeof x === "string" && ((x = "hello") && x) : number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>((x = "hello") && x) : number | string
|
||||
>(x = "hello") && x : number | string
|
||||
>(x = "hello") : string
|
||||
>x = "hello" : string
|
||||
>x : number | string
|
||||
>"hello" : string
|
||||
>x : number | string
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
>foo4 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>typeof x !== "string" // string | number | boolean && typeof x !== "number" // number | boolean && x : boolean
|
||||
>typeof x !== "string" // string | number | boolean && typeof x !== "number" : boolean
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
&& typeof x !== "number" // number | boolean
|
||||
>typeof x !== "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
&& x; // boolean
|
||||
>x : boolean
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
>b : number | boolean
|
||||
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>typeof x !== "string" // string | number | boolean && ((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
>((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean
|
||||
>(b = x) && (typeof x !== "number" // number | boolean && x) : boolean
|
||||
>(b = x) : number | boolean
|
||||
>b = x : number | boolean
|
||||
>b : number | boolean
|
||||
>x : number | boolean
|
||||
>(typeof x !== "number" // number | boolean && x) : boolean
|
||||
>typeof x !== "number" // number | boolean && x : boolean
|
||||
>typeof x !== "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
&& x)); // boolean
|
||||
>x : boolean
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
>foo6 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
>typeof x !== "string" // string | number | boolean && (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
>(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean
|
||||
>typeof x !== "number" // number | boolean ? x // boolean : x === 10 : boolean
|
||||
>typeof x !== "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
? x // boolean
|
||||
>x : boolean
|
||||
|
||||
: x === 10) // number
|
||||
>x === 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : (x: number | string | boolean) => string
|
||||
>x : number | string | boolean
|
||||
|
||||
var y: number| boolean | string;
|
||||
>y : number | boolean | string
|
||||
|
||||
var z: number| boolean | string;
|
||||
>z : number | boolean | string
|
||||
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x !== "string"
|
||||
>typeof x !== "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
&& ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
>((z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string
|
||||
>(z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string
|
||||
>(z = x) : number | string | boolean
|
||||
>z = x : number | string | boolean
|
||||
>z : number | boolean | string
|
||||
>x : number | string | boolean
|
||||
|
||||
&& (typeof x === "number"
|
||||
>(typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string
|
||||
>typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()) : string
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
>(x = 10 && x.toString()) : string
|
||||
>x = 10 && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>10 && x.toString() : string
|
||||
>10 : number
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
>(y = x && x.toString()) : string
|
||||
>y = x && x.toString() : string
|
||||
>y : number | boolean | string
|
||||
>x && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
>foo8 : (x: number | string) => number
|
||||
>x : number | string
|
||||
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x !== "string"
|
||||
>typeof x !== "string" && (x = 10) // change x - number| string && (typeof x === "number" ? x // number : x.length) : number
|
||||
>typeof x !== "string" && (x = 10) : number
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
&& (x = 10) // change x - number| string
|
||||
>(x = 10) : number
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
|
||||
&& (typeof x === "number"
|
||||
>(typeof x === "number" ? x // number : x.length) : number
|
||||
>typeof x === "number" ? x // number : x.length : number
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"number" : string
|
||||
|
||||
? x // number
|
||||
>x : number
|
||||
|
||||
: x.length); // string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts(43,22): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts(45,21): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts (2 errors) ====
|
||||
// In the right operand of a || operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when false,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
return typeof x !== "string" || x.length === 10; // string
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
// modify x in right hand operand
|
||||
return typeof x !== "string" || ((x = 10) || x); // string | number
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x !== "string" || ((x = "hello") || x); // string | number
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| typeof x === "number" // number | boolean
|
||||
|| x; // boolean
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
|| x)); // boolean
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
// Mixing typeguard
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10) // number
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
var y: number| boolean | string;
|
||||
var z: number| boolean | string;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x === "string"
|
||||
|| ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
|| (typeof x === "number"
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x === "string"
|
||||
|| (x = 10) // change x - number| string
|
||||
|| (typeof x === "number"
|
||||
? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts ===
|
||||
// In the right operand of a || operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when false,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
>foo : Symbol(foo, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13))
|
||||
|
||||
return typeof x !== "string" || x.length === 10; // string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : Symbol(foo2, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 5, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14))
|
||||
|
||||
// modify x in right hand operand
|
||||
return typeof x !== "string" || ((x = 10) || x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14))
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : Symbol(foo3, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 9, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14))
|
||||
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x !== "string" || ((x = "hello") || x); // string | number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14))
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
>foo4 : Symbol(foo4, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 13, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14))
|
||||
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14))
|
||||
|
||||
|| typeof x === "number" // number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14))
|
||||
|
||||
|| x; // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14))
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : Symbol(foo5, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 18, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14))
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
>b : Symbol(b, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 21, 7))
|
||||
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14))
|
||||
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
>b : Symbol(b, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 21, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14))
|
||||
|
||||
|| x)); // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14))
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
>foo6 : Symbol(foo6, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 25, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14))
|
||||
|
||||
// Mixing typeguard
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14))
|
||||
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14))
|
||||
|
||||
? x // boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14))
|
||||
|
||||
: x === 10) // number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14))
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : Symbol(foo7, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 32, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
|
||||
var y: number| boolean | string;
|
||||
>y : Symbol(y, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 34, 7))
|
||||
|
||||
var z: number| boolean | string;
|
||||
>z : Symbol(z, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 35, 7))
|
||||
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
|
||||
|| ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
>z : Symbol(z, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 35, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
|
||||
|| (typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
>y : Symbol(y, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 34, 7))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
>x.toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14))
|
||||
>toString : Symbol(toString, Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26))
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
>foo8 : Symbol(foo8, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 45, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x === "string"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
|
||||
|| (x = 10) // change x - number| string
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
|
||||
|| (typeof x === "number"
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
|
||||
? x // number
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
|
||||
: x.length); // string
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
>x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts ===
|
||||
// In the right operand of a || operation,
|
||||
// the type of a variable or parameter is narrowed by any type guard in the left operand when false,
|
||||
// provided the right operand contains no assignments to the variable or parameter.
|
||||
function foo(x: number | string) {
|
||||
>foo : (x: number | string) => boolean
|
||||
>x : number | string
|
||||
|
||||
return typeof x !== "string" || x.length === 10; // string
|
||||
>typeof x !== "string" || x.length === 10 : boolean
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>x.length === 10 : boolean
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
>10 : number
|
||||
}
|
||||
function foo2(x: number | string) {
|
||||
>foo2 : (x: number | string) => boolean | number | string
|
||||
>x : number | string
|
||||
|
||||
// modify x in right hand operand
|
||||
return typeof x !== "string" || ((x = 10) || x); // string | number
|
||||
>typeof x !== "string" || ((x = 10) || x) : boolean | number | string
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>((x = 10) || x) : number | string
|
||||
>(x = 10) || x : number | string
|
||||
>(x = 10) : number
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
>x : number | string
|
||||
}
|
||||
function foo3(x: number | string) {
|
||||
>foo3 : (x: number | string) => boolean | string | number
|
||||
>x : number | string
|
||||
|
||||
// modify x in right hand operand with string type itself
|
||||
return typeof x !== "string" || ((x = "hello") || x); // string | number
|
||||
>typeof x !== "string" || ((x = "hello") || x) : boolean | string | number
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
>((x = "hello") || x) : string | number
|
||||
>(x = "hello") || x : string | number
|
||||
>(x = "hello") : string
|
||||
>x = "hello" : string
|
||||
>x : number | string
|
||||
>"hello" : string
|
||||
>x : number | string
|
||||
}
|
||||
function foo4(x: number | string | boolean) {
|
||||
>foo4 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>typeof x === "string" // string | number | boolean || typeof x === "number" // number | boolean || x : boolean
|
||||
>typeof x === "string" // string | number | boolean || typeof x === "number" : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
|| typeof x === "number" // number | boolean
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
|| x; // boolean
|
||||
>x : boolean
|
||||
}
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : (x: number | string | boolean) => boolean | number
|
||||
>x : number | string | boolean
|
||||
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b: number | boolean;
|
||||
>b : number | boolean
|
||||
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>typeof x === "string" // string | number | boolean || ((b = x) || (typeof x === "number" // number | boolean || x)) : boolean | number
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
>((b = x) || (typeof x === "number" // number | boolean || x)) : number | boolean
|
||||
>(b = x) || (typeof x === "number" // number | boolean || x) : number | boolean
|
||||
>(b = x) : number | boolean
|
||||
>b = x : number | boolean
|
||||
>b : number | boolean
|
||||
>x : number | boolean
|
||||
>(typeof x === "number" // number | boolean || x) : boolean
|
||||
>typeof x === "number" // number | boolean || x : boolean
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
|| x)); // boolean
|
||||
>x : boolean
|
||||
}
|
||||
function foo6(x: number | string | boolean) {
|
||||
>foo6 : (x: number | string | boolean) => boolean
|
||||
>x : number | string | boolean
|
||||
|
||||
// Mixing typeguard
|
||||
return typeof x === "string" // string | number | boolean
|
||||
>typeof x === "string" // string | number | boolean || (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
>(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean
|
||||
>typeof x !== "number" // number | boolean ? x // boolean : x === 10 : boolean
|
||||
>typeof x !== "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | boolean
|
||||
>"number" : string
|
||||
|
||||
? x // boolean
|
||||
>x : boolean
|
||||
|
||||
: x === 10) // number
|
||||
>x === 10 : boolean
|
||||
>x : number
|
||||
>10 : number
|
||||
}
|
||||
function foo7(x: number | string | boolean) {
|
||||
>foo7 : (x: number | string | boolean) => boolean | number | string
|
||||
>x : number | string | boolean
|
||||
|
||||
var y: number| boolean | string;
|
||||
>y : number | boolean | string
|
||||
|
||||
var z: number| boolean | string;
|
||||
>z : number | boolean | string
|
||||
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : boolean | number | string
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"string" : string
|
||||
|
||||
|| ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
>((z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : number | string | boolean
|
||||
>(z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : number | string | boolean
|
||||
>(z = x) : number | string | boolean
|
||||
>z = x : number | string | boolean
|
||||
>z : number | boolean | string
|
||||
>x : number | string | boolean
|
||||
|
||||
|| (typeof x === "number"
|
||||
>(typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string
|
||||
>typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()) : string
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string | boolean
|
||||
>"number" : string
|
||||
|
||||
// change value of x
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
>(x = 10 && x.toString()) : string
|
||||
>x = 10 && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>10 && x.toString() : string
|
||||
>10 : number
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
|
||||
// do not change value
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
>(y = x && x.toString()) : string
|
||||
>y = x && x.toString() : string
|
||||
>y : number | boolean | string
|
||||
>x && x.toString() : string
|
||||
>x : number | string | boolean
|
||||
>x.toString() : string
|
||||
>x.toString : ((radix?: number) => string) | (() => string)
|
||||
>x : number | string | boolean
|
||||
>toString : ((radix?: number) => string) | (() => string)
|
||||
}
|
||||
function foo8(x: number | string) {
|
||||
>foo8 : (x: number | string) => boolean | number
|
||||
>x : number | string
|
||||
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x === "string"
|
||||
>typeof x === "string" || (x = 10) // change x - number| string || (typeof x === "number" ? x // number : x.length) : boolean | number
|
||||
>typeof x === "string" || (x = 10) : boolean | number
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"string" : string
|
||||
|
||||
|| (x = 10) // change x - number| string
|
||||
>(x = 10) : number
|
||||
>x = 10 : number
|
||||
>x : number | string
|
||||
>10 : number
|
||||
|
||||
|| (typeof x === "number"
|
||||
>(typeof x === "number" ? x // number : x.length) : number
|
||||
>typeof x === "number" ? x // number : x.length : number
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : number | string
|
||||
>"number" : string
|
||||
|
||||
? x // number
|
||||
>x : number
|
||||
|
||||
: x.length); // string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
@@ -12,29 +12,25 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(30,1): error TS23
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(31,1): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(36,49): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(37,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(40,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(41,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(42,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(43,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(46,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(47,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(48,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(49,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(40,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(42,49): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(43,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(47,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(48,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(49,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(55,45): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(56,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(59,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(60,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(61,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(62,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(63,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(66,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(67,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(68,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(59,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(61,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(62,45): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(63,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(67,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(68,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (34 errors) ====
|
||||
==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (30 errors) ====
|
||||
var numOrDate: number | Date;
|
||||
var strOrBoolean: string | boolean;
|
||||
var strOrNum: string | number;
|
||||
@@ -80,7 +76,7 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
unionWithDifferentParameterCount();// no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
@@ -91,7 +87,7 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
|
||||
var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; };
|
||||
var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; };
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
strOrNum = unionWithOptionalParameter1('hello', 10);
|
||||
strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type
|
||||
@@ -104,30 +100,26 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2
|
||||
var unionWithOptionalParameter2: { (a: string, b?: number): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithOptionalParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = unionWithOptionalParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; };
|
||||
strOrNum = unionWithOptionalParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithOptionalParameter3('hello');
|
||||
strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number };
|
||||
strOrNum = unionWithRestParameter1('hello');
|
||||
@@ -143,33 +135,31 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2
|
||||
var unionWithRestParameter2: { (a: string, ...b: number[]): string; } | { (a: string, b: number): number };
|
||||
strOrNum = unionWithRestParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithRestParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = unionWithRestParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: string): number };
|
||||
strOrNum = unionWithRestParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
strOrNum = unionWithRestParameter3('hello');
|
||||
strOrNum = unionWithRestParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = unionWithRestParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ unionOfDifferentNumberOfSignatures(); // error - no call signatures
|
||||
unionOfDifferentNumberOfSignatures(10); // error - no call signatures
|
||||
unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures
|
||||
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
unionWithDifferentParameterCount();// no call signature
|
||||
unionWithDifferentParameterCount("hello");// no call signature
|
||||
unionWithDifferentParameterCount("hello", 10);// no call signature
|
||||
|
||||
var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; };
|
||||
var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; };
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
strOrNum = unionWithOptionalParameter1('hello', 10);
|
||||
strOrNum = unionWithOptionalParameter1('hello', "hello"); // error in parameter type
|
||||
@@ -44,7 +44,7 @@ strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signa
|
||||
strOrNum = unionWithOptionalParameter2(); // error no call signature
|
||||
|
||||
var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; };
|
||||
strOrNum = unionWithOptionalParameter3('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello');
|
||||
strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
@@ -64,11 +64,13 @@ strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithRestParameter2(); // error no call signature
|
||||
|
||||
var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: string): number };
|
||||
strOrNum = unionWithRestParameter3('hello'); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello');
|
||||
strOrNum = unionWithRestParameter3('hello', 10); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithRestParameter3(); // error no call signature
|
||||
strOrNum = unionWithRestParameter3(); // error no call signature
|
||||
|
||||
|
||||
|
||||
//// [unionTypeCallSignatures.js]
|
||||
var numOrDate;
|
||||
@@ -108,7 +110,7 @@ strOrNum = unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter2(); // error no call signature
|
||||
var unionWithOptionalParameter3;
|
||||
strOrNum = unionWithOptionalParameter3('hello'); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello');
|
||||
strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithOptionalParameter3(); // error no call signature
|
||||
@@ -125,7 +127,7 @@ strOrNum = unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
strOrNum = unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
strOrNum = unionWithRestParameter2(); // error no call signature
|
||||
var unionWithRestParameter3;
|
||||
strOrNum = unionWithRestParameter3('hello'); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello');
|
||||
strOrNum = unionWithRestParameter3('hello', 10); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature
|
||||
strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//// [unionTypeCallSignatures2.ts]
|
||||
interface A {
|
||||
(x: number): number;
|
||||
(x: string, y?: string): boolean;
|
||||
(x: Date): void;
|
||||
<T>(x: T[]): T[];
|
||||
}
|
||||
|
||||
interface B {
|
||||
(x: number): number;
|
||||
(x: string): string;
|
||||
(x: Date): void;
|
||||
<T>(x: T[]): T[];
|
||||
}
|
||||
|
||||
interface C {
|
||||
(x: string, ...y: string[]): number;
|
||||
(x: number, s?: string): number;
|
||||
<T>(x: T[]): T[];
|
||||
}
|
||||
|
||||
var f1: A | B | C;
|
||||
var n1 = f1(42); // number
|
||||
var s1 = f1("abc"); // boolean | string | number
|
||||
var a1 = f1([true, false]); // boolean[]
|
||||
|
||||
var f2: C | B | A;
|
||||
var n2 = f2(42); // number
|
||||
var s2 = f2("abc"); // number | string | boolean
|
||||
var a2 = f2([true, false]); // boolean[]
|
||||
|
||||
var f3: B | A | C;
|
||||
var n3 = f3(42); // number
|
||||
var s3 = f3("abc"); // string | boolean | number
|
||||
var a3 = f3([true, false]); // boolean[]
|
||||
|
||||
|
||||
|
||||
//// [unionTypeCallSignatures2.js]
|
||||
var f1;
|
||||
var n1 = f1(42); // number
|
||||
var s1 = f1("abc"); // boolean | string | number
|
||||
var a1 = f1([true, false]); // boolean[]
|
||||
var f2;
|
||||
var n2 = f2(42); // number
|
||||
var s2 = f2("abc"); // number | string | boolean
|
||||
var a2 = f2([true, false]); // boolean[]
|
||||
var f3;
|
||||
var n3 = f3(42); // number
|
||||
var s3 = f3("abc"); // string | boolean | number
|
||||
var a3 = f3([true, false]); // boolean[]
|
||||
@@ -0,0 +1,115 @@
|
||||
=== tests/cases/conformance/types/union/unionTypeCallSignatures2.ts ===
|
||||
interface A {
|
||||
>A : Symbol(A, Decl(unionTypeCallSignatures2.ts, 0, 0))
|
||||
|
||||
(x: number): number;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 1, 5))
|
||||
|
||||
(x: string, y?: string): boolean;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 2, 5))
|
||||
>y : Symbol(y, Decl(unionTypeCallSignatures2.ts, 2, 15))
|
||||
|
||||
(x: Date): void;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 3, 5))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 4, 5))
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 4, 8))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 4, 5))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 4, 5))
|
||||
}
|
||||
|
||||
interface B {
|
||||
>B : Symbol(B, Decl(unionTypeCallSignatures2.ts, 5, 1))
|
||||
|
||||
(x: number): number;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 8, 5))
|
||||
|
||||
(x: string): string;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 9, 5))
|
||||
|
||||
(x: Date): void;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 10, 5))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 11, 5))
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 11, 8))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 11, 5))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 11, 5))
|
||||
}
|
||||
|
||||
interface C {
|
||||
>C : Symbol(C, Decl(unionTypeCallSignatures2.ts, 12, 1))
|
||||
|
||||
(x: string, ...y: string[]): number;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 15, 5))
|
||||
>y : Symbol(y, Decl(unionTypeCallSignatures2.ts, 15, 15))
|
||||
|
||||
(x: number, s?: string): number;
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 16, 5))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures2.ts, 16, 15))
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 17, 5))
|
||||
>x : Symbol(x, Decl(unionTypeCallSignatures2.ts, 17, 8))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 17, 5))
|
||||
>T : Symbol(T, Decl(unionTypeCallSignatures2.ts, 17, 5))
|
||||
}
|
||||
|
||||
var f1: A | B | C;
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures2.ts, 20, 3))
|
||||
>A : Symbol(A, Decl(unionTypeCallSignatures2.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(unionTypeCallSignatures2.ts, 5, 1))
|
||||
>C : Symbol(C, Decl(unionTypeCallSignatures2.ts, 12, 1))
|
||||
|
||||
var n1 = f1(42); // number
|
||||
>n1 : Symbol(n1, Decl(unionTypeCallSignatures2.ts, 21, 3))
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures2.ts, 20, 3))
|
||||
|
||||
var s1 = f1("abc"); // boolean | string | number
|
||||
>s1 : Symbol(s1, Decl(unionTypeCallSignatures2.ts, 22, 3))
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures2.ts, 20, 3))
|
||||
|
||||
var a1 = f1([true, false]); // boolean[]
|
||||
>a1 : Symbol(a1, Decl(unionTypeCallSignatures2.ts, 23, 3))
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures2.ts, 20, 3))
|
||||
|
||||
var f2: C | B | A;
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures2.ts, 25, 3))
|
||||
>C : Symbol(C, Decl(unionTypeCallSignatures2.ts, 12, 1))
|
||||
>B : Symbol(B, Decl(unionTypeCallSignatures2.ts, 5, 1))
|
||||
>A : Symbol(A, Decl(unionTypeCallSignatures2.ts, 0, 0))
|
||||
|
||||
var n2 = f2(42); // number
|
||||
>n2 : Symbol(n2, Decl(unionTypeCallSignatures2.ts, 26, 3))
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures2.ts, 25, 3))
|
||||
|
||||
var s2 = f2("abc"); // number | string | boolean
|
||||
>s2 : Symbol(s2, Decl(unionTypeCallSignatures2.ts, 27, 3))
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures2.ts, 25, 3))
|
||||
|
||||
var a2 = f2([true, false]); // boolean[]
|
||||
>a2 : Symbol(a2, Decl(unionTypeCallSignatures2.ts, 28, 3))
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures2.ts, 25, 3))
|
||||
|
||||
var f3: B | A | C;
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures2.ts, 30, 3))
|
||||
>B : Symbol(B, Decl(unionTypeCallSignatures2.ts, 5, 1))
|
||||
>A : Symbol(A, Decl(unionTypeCallSignatures2.ts, 0, 0))
|
||||
>C : Symbol(C, Decl(unionTypeCallSignatures2.ts, 12, 1))
|
||||
|
||||
var n3 = f3(42); // number
|
||||
>n3 : Symbol(n3, Decl(unionTypeCallSignatures2.ts, 31, 3))
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures2.ts, 30, 3))
|
||||
|
||||
var s3 = f3("abc"); // string | boolean | number
|
||||
>s3 : Symbol(s3, Decl(unionTypeCallSignatures2.ts, 32, 3))
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures2.ts, 30, 3))
|
||||
|
||||
var a3 = f3([true, false]); // boolean[]
|
||||
>a3 : Symbol(a3, Decl(unionTypeCallSignatures2.ts, 33, 3))
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures2.ts, 30, 3))
|
||||
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
=== tests/cases/conformance/types/union/unionTypeCallSignatures2.ts ===
|
||||
interface A {
|
||||
>A : A
|
||||
|
||||
(x: number): number;
|
||||
>x : number
|
||||
|
||||
(x: string, y?: string): boolean;
|
||||
>x : string
|
||||
>y : string
|
||||
|
||||
(x: Date): void;
|
||||
>x : Date
|
||||
>Date : Date
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : T
|
||||
>x : T[]
|
||||
>T : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
interface B {
|
||||
>B : B
|
||||
|
||||
(x: number): number;
|
||||
>x : number
|
||||
|
||||
(x: string): string;
|
||||
>x : string
|
||||
|
||||
(x: Date): void;
|
||||
>x : Date
|
||||
>Date : Date
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : T
|
||||
>x : T[]
|
||||
>T : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
interface C {
|
||||
>C : C
|
||||
|
||||
(x: string, ...y: string[]): number;
|
||||
>x : string
|
||||
>y : string[]
|
||||
|
||||
(x: number, s?: string): number;
|
||||
>x : number
|
||||
>s : string
|
||||
|
||||
<T>(x: T[]): T[];
|
||||
>T : T
|
||||
>x : T[]
|
||||
>T : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
var f1: A | B | C;
|
||||
>f1 : A | B | C
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
var n1 = f1(42); // number
|
||||
>n1 : number
|
||||
>f1(42) : number
|
||||
>f1 : A | B | C
|
||||
>42 : number
|
||||
|
||||
var s1 = f1("abc"); // boolean | string | number
|
||||
>s1 : boolean | string | number
|
||||
>f1("abc") : boolean | string | number
|
||||
>f1 : A | B | C
|
||||
>"abc" : string
|
||||
|
||||
var a1 = f1([true, false]); // boolean[]
|
||||
>a1 : boolean[]
|
||||
>f1([true, false]) : boolean[]
|
||||
>f1 : A | B | C
|
||||
>[true, false] : boolean[]
|
||||
>true : boolean
|
||||
>false : boolean
|
||||
|
||||
var f2: C | B | A;
|
||||
>f2 : C | B | A
|
||||
>C : C
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
var n2 = f2(42); // number
|
||||
>n2 : number
|
||||
>f2(42) : number
|
||||
>f2 : C | B | A
|
||||
>42 : number
|
||||
|
||||
var s2 = f2("abc"); // number | string | boolean
|
||||
>s2 : number | string | boolean
|
||||
>f2("abc") : number | string | boolean
|
||||
>f2 : C | B | A
|
||||
>"abc" : string
|
||||
|
||||
var a2 = f2([true, false]); // boolean[]
|
||||
>a2 : boolean[]
|
||||
>f2([true, false]) : boolean[]
|
||||
>f2 : C | B | A
|
||||
>[true, false] : boolean[]
|
||||
>true : boolean
|
||||
>false : boolean
|
||||
|
||||
var f3: B | A | C;
|
||||
>f3 : B | A | C
|
||||
>B : B
|
||||
>A : A
|
||||
>C : C
|
||||
|
||||
var n3 = f3(42); // number
|
||||
>n3 : number
|
||||
>f3(42) : number
|
||||
>f3 : B | A | C
|
||||
>42 : number
|
||||
|
||||
var s3 = f3("abc"); // string | boolean | number
|
||||
>s3 : string | boolean | number
|
||||
>f3("abc") : string | boolean | number
|
||||
>f3 : B | A | C
|
||||
>"abc" : string
|
||||
|
||||
var a3 = f3([true, false]); // boolean[]
|
||||
>a3 : boolean[]
|
||||
>f3([true, false]) : boolean[]
|
||||
>f3 : B | A | C
|
||||
>[true, false] : boolean[]
|
||||
>true : boolean
|
||||
>false : boolean
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//// [unionTypeCallSignatures3.ts]
|
||||
function f1(s: string) { }
|
||||
function f2(s?: string) { }
|
||||
function f3(...s: string[]) { }
|
||||
function f4(s: string, s2?: string) { }
|
||||
function f5(s?: string, n?: number) { }
|
||||
function f6(s?: string, ...n: number[]) { }
|
||||
function f7(s: string, ...sRest: string[]) { }
|
||||
|
||||
var fUnion: typeof f1 | typeof f2 | typeof f3 | typeof f4 | typeof f5 | typeof f6 | typeof f7;
|
||||
|
||||
fUnion(""); // All constituents can be called by passing a single string.
|
||||
|
||||
|
||||
//// [unionTypeCallSignatures3.js]
|
||||
function f1(s) { }
|
||||
function f2(s) { }
|
||||
function f3() {
|
||||
var s = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
s[_i - 0] = arguments[_i];
|
||||
}
|
||||
}
|
||||
function f4(s, s2) { }
|
||||
function f5(s, n) { }
|
||||
function f6(s) {
|
||||
var n = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
n[_i - 1] = arguments[_i];
|
||||
}
|
||||
}
|
||||
function f7(s) {
|
||||
var sRest = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
sRest[_i - 1] = arguments[_i];
|
||||
}
|
||||
}
|
||||
var fUnion;
|
||||
fUnion(""); // All constituents can be called by passing a single string.
|
||||
@@ -0,0 +1,46 @@
|
||||
=== tests/cases/conformance/types/union/unionTypeCallSignatures3.ts ===
|
||||
function f1(s: string) { }
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures3.ts, 0, 0))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 0, 12))
|
||||
|
||||
function f2(s?: string) { }
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures3.ts, 0, 26))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 1, 12))
|
||||
|
||||
function f3(...s: string[]) { }
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures3.ts, 1, 27))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 2, 12))
|
||||
|
||||
function f4(s: string, s2?: string) { }
|
||||
>f4 : Symbol(f4, Decl(unionTypeCallSignatures3.ts, 2, 31))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 3, 12))
|
||||
>s2 : Symbol(s2, Decl(unionTypeCallSignatures3.ts, 3, 22))
|
||||
|
||||
function f5(s?: string, n?: number) { }
|
||||
>f5 : Symbol(f5, Decl(unionTypeCallSignatures3.ts, 3, 39))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 4, 12))
|
||||
>n : Symbol(n, Decl(unionTypeCallSignatures3.ts, 4, 23))
|
||||
|
||||
function f6(s?: string, ...n: number[]) { }
|
||||
>f6 : Symbol(f6, Decl(unionTypeCallSignatures3.ts, 4, 39))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 5, 12))
|
||||
>n : Symbol(n, Decl(unionTypeCallSignatures3.ts, 5, 23))
|
||||
|
||||
function f7(s: string, ...sRest: string[]) { }
|
||||
>f7 : Symbol(f7, Decl(unionTypeCallSignatures3.ts, 5, 43))
|
||||
>s : Symbol(s, Decl(unionTypeCallSignatures3.ts, 6, 12))
|
||||
>sRest : Symbol(sRest, Decl(unionTypeCallSignatures3.ts, 6, 22))
|
||||
|
||||
var fUnion: typeof f1 | typeof f2 | typeof f3 | typeof f4 | typeof f5 | typeof f6 | typeof f7;
|
||||
>fUnion : Symbol(fUnion, Decl(unionTypeCallSignatures3.ts, 8, 3))
|
||||
>f1 : Symbol(f1, Decl(unionTypeCallSignatures3.ts, 0, 0))
|
||||
>f2 : Symbol(f2, Decl(unionTypeCallSignatures3.ts, 0, 26))
|
||||
>f3 : Symbol(f3, Decl(unionTypeCallSignatures3.ts, 1, 27))
|
||||
>f4 : Symbol(f4, Decl(unionTypeCallSignatures3.ts, 2, 31))
|
||||
>f5 : Symbol(f5, Decl(unionTypeCallSignatures3.ts, 3, 39))
|
||||
>f6 : Symbol(f6, Decl(unionTypeCallSignatures3.ts, 4, 39))
|
||||
>f7 : Symbol(f7, Decl(unionTypeCallSignatures3.ts, 5, 43))
|
||||
|
||||
fUnion(""); // All constituents can be called by passing a single string.
|
||||
>fUnion : Symbol(fUnion, Decl(unionTypeCallSignatures3.ts, 8, 3))
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
=== tests/cases/conformance/types/union/unionTypeCallSignatures3.ts ===
|
||||
function f1(s: string) { }
|
||||
>f1 : (s: string) => void
|
||||
>s : string
|
||||
|
||||
function f2(s?: string) { }
|
||||
>f2 : (s?: string) => void
|
||||
>s : string
|
||||
|
||||
function f3(...s: string[]) { }
|
||||
>f3 : (...s: string[]) => void
|
||||
>s : string[]
|
||||
|
||||
function f4(s: string, s2?: string) { }
|
||||
>f4 : (s: string, s2?: string) => void
|
||||
>s : string
|
||||
>s2 : string
|
||||
|
||||
function f5(s?: string, n?: number) { }
|
||||
>f5 : (s?: string, n?: number) => void
|
||||
>s : string
|
||||
>n : number
|
||||
|
||||
function f6(s?: string, ...n: number[]) { }
|
||||
>f6 : (s?: string, ...n: number[]) => void
|
||||
>s : string
|
||||
>n : number[]
|
||||
|
||||
function f7(s: string, ...sRest: string[]) { }
|
||||
>f7 : (s: string, ...sRest: string[]) => void
|
||||
>s : string
|
||||
>sRest : string[]
|
||||
|
||||
var fUnion: typeof f1 | typeof f2 | typeof f3 | typeof f4 | typeof f5 | typeof f6 | typeof f7;
|
||||
>fUnion : ((s: string) => void) | ((s?: string) => void) | ((...s: string[]) => void) | ((s: string, s2?: string) => void) | ((s?: string, n?: number) => void) | ((s?: string, ...n: number[]) => void) | ((s: string, ...sRest: string[]) => void)
|
||||
>f1 : (s: string) => void
|
||||
>f2 : (s?: string) => void
|
||||
>f3 : (...s: string[]) => void
|
||||
>f4 : (s: string, s2?: string) => void
|
||||
>f5 : (s?: string, n?: number) => void
|
||||
>f6 : (s?: string, ...n: number[]) => void
|
||||
>f7 : (s: string, ...sRest: string[]) => void
|
||||
|
||||
fUnion(""); // All constituents can be called by passing a single string.
|
||||
>fUnion("") : void
|
||||
>fUnion : ((s: string) => void) | ((s?: string) => void) | ((...s: string[]) => void) | ((s: string, s2?: string) => void) | ((s?: string, n?: number) => void) | ((s?: string, ...n: number[]) => void) | ((s: string, ...sRest: string[]) => void)
|
||||
>"" : string
|
||||
|
||||
@@ -12,29 +12,25 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(30,1): error
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(31,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(36,53): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(37,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(40,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(41,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(42,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(43,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(46,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(47,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(48,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(49,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(40,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(42,53): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(43,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(47,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(48,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(49,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(55,49): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(56,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(59,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(60,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(61,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(62,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(63,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(66,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(67,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(68,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(69,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(59,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(61,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(62,49): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(63,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(67,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(68,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(69,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/union/unionTypeConstructSignatures.ts (34 errors) ====
|
||||
==== tests/cases/conformance/types/union/unionTypeConstructSignatures.ts (30 errors) ====
|
||||
var numOrDate: number | Date;
|
||||
var strOrBoolean: string | boolean;
|
||||
var strOrNum: string | number;
|
||||
@@ -104,30 +100,26 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro
|
||||
var unionWithOptionalParameter2: { new (a: string, b?: number): string; } | { new (a: string, b: number): number };
|
||||
strOrNum = new unionWithOptionalParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithOptionalParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
strOrNum = new unionWithOptionalParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = new unionWithOptionalParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithOptionalParameter3: { new (a: string, b?: number): string; } | { new (a: string): number; };
|
||||
strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithOptionalParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithRestParameter1: { new (a: string, ...b: number[]): string; } | { new (a: string, ...b: number[]): number };
|
||||
strOrNum = new unionWithRestParameter1('hello');
|
||||
@@ -143,33 +135,29 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro
|
||||
var unionWithRestParameter2: { new (a: string, ...b: number[]): string; } | { new (a: string, b: number): number };
|
||||
strOrNum = new unionWithRestParameter2('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithRestParameter2('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
strOrNum = new unionWithRestParameter2('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithRestParameter2('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
strOrNum = new unionWithRestParameter2(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
|
||||
var unionWithRestParameter3: { new (a: string, ...b: number[]): string; } | { new (a: string): number };
|
||||
strOrNum = new unionWithRestParameter3('hello'); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
strOrNum = new unionWithRestParameter3(); // error no call signature
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
@@ -0,0 +1,15 @@
|
||||
function foo(/*c1*/ x: any) { }
|
||||
foo(/*c2*/ 1);
|
||||
foo(/*c3*/ function () { });
|
||||
foo(
|
||||
/*c4*/
|
||||
() => { });
|
||||
foo(
|
||||
/*c5*/
|
||||
/*c6*/
|
||||
() => { });
|
||||
foo(/*c7*/
|
||||
() => { });
|
||||
foo(
|
||||
/*c7*/
|
||||
/*c8*/() => { });
|
||||
@@ -0,0 +1,10 @@
|
||||
function foo(/*c1*/ x: any, /*d1*/ y: any,/*e1*/w?: any) { }
|
||||
var a, b: any;
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
|
||||
foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
|
||||
foo(
|
||||
/*c4*/ function () { },
|
||||
/*d4*/() => { },
|
||||
/*e4*/
|
||||
/*e5*/ "hello");
|
||||
@@ -0,0 +1,13 @@
|
||||
var resolve = {
|
||||
id: /*! @ngInject */ (details: any) => details.id,
|
||||
id1: /* c1 */ "hello",
|
||||
id2:
|
||||
/*! @ngInject */ (details: any) => details.id,
|
||||
id3:
|
||||
/*! @ngInject */
|
||||
(details: any) => details.id,
|
||||
id4:
|
||||
/*! @ngInject */
|
||||
/* C2 */
|
||||
(details: any) => details.id,
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
//@jsx: preserve
|
||||
var t02 = <a>{0}#</a>;
|
||||
var t03 = <a>#{0}</a>;
|
||||
var t04 = <a>#{0}#</a>;
|
||||
var t05 = <a>#<i></i></a>;
|
||||
var t06 = <a>#<i></i></a>;
|
||||
var t07 = <a>#<i>#</i></a>;
|
||||
var t08 = <a><i></i>#</a>;
|
||||
var t09 = <a>#<i></i>#</a>;
|
||||
var t10 = <a><i/>#</a>;
|
||||
var t11 = <a>#<i/></a>;
|
||||
var t12 = <a>#</a>;
|
||||
@@ -0,0 +1,6 @@
|
||||
// @declaration: true
|
||||
|
||||
interface C {
|
||||
({p: name}): any;
|
||||
new ({p: boolean}): any;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// @module: system
|
||||
// @isolatedModules: true
|
||||
|
||||
function foo() {
|
||||
return a;
|
||||
}
|
||||
|
||||
import {a} from "foo";
|
||||
export {foo}
|
||||
|
||||
var x = 1;
|
||||
export {foo as b}
|
||||
@@ -0,0 +1,34 @@
|
||||
// @module: system
|
||||
// @isolatedModules: true
|
||||
|
||||
// @filename: file1.ts
|
||||
|
||||
import * as moduleB from "./file2"
|
||||
|
||||
declare function use(v: any): void;
|
||||
|
||||
use(moduleB.value);
|
||||
use(moduleB.moduleC);
|
||||
use(moduleB.moduleCStar);
|
||||
|
||||
// @filename: file2.ts
|
||||
|
||||
import * as moduleCStar from "./file3"
|
||||
import {value2} from "./file4"
|
||||
import moduleC from "./file3"
|
||||
import {value} from "./file3"
|
||||
|
||||
export {
|
||||
moduleCStar,
|
||||
moduleC,
|
||||
value
|
||||
}
|
||||
|
||||
// @filename: file3.ts
|
||||
|
||||
export var value = "youpi";
|
||||
export default value;
|
||||
|
||||
// @filename: file4.ts
|
||||
|
||||
export var value2 = "v";
|
||||
@@ -0,0 +1,13 @@
|
||||
// @module: system
|
||||
// @isolatedModules: true
|
||||
|
||||
import * as x from "foo";
|
||||
import * as y from "bar";
|
||||
export * from "foo";
|
||||
export * from "bar"
|
||||
export {x}
|
||||
export {y}
|
||||
import {a1, b1, c1 as d1} from "foo";
|
||||
export {a2, b2, c2 as d2} from "bar";
|
||||
|
||||
x,y,a1,b1,d1;
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES5
|
||||
// @module: AMD
|
||||
// @declaration: true
|
||||
|
||||
export type callback<T> = () => T;
|
||||
|
||||
export type CallbackArray<T extends callback> = () => T;
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: ES5
|
||||
// @module: AMD
|
||||
// @declaration: true
|
||||
|
||||
export type A<a> = { value: a };
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
abstract class A { }
|
||||
|
||||
// var AA: typeof A;
|
||||
var AAA: new() => A;
|
||||
|
||||
// AA = A; // okay
|
||||
AAA = A; // error.
|
||||
AAA = "asdf";
|
||||
@@ -0,0 +1,10 @@
|
||||
// @module: commonjs
|
||||
// @Filename: foo1.ts
|
||||
class x{}
|
||||
|
||||
export = x;
|
||||
|
||||
// @Filename: foo2.ts
|
||||
import foo1 = require('./foo1');
|
||||
var x = foo1;
|
||||
class y extends x {}
|
||||
@@ -0,0 +1,17 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
// @filename: service.ts
|
||||
export default class Service {
|
||||
}
|
||||
// @filename: component.ts
|
||||
import Service from "./service";
|
||||
|
||||
declare var decorator: any;
|
||||
|
||||
@decorator
|
||||
class MyComponent {
|
||||
constructor(public Service: Service) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// @module: commonjs
|
||||
// @Filename: foo1.ts
|
||||
class x{}
|
||||
export = x;
|
||||
|
||||
// @Filename: foo2.ts
|
||||
import foo1 = require('./foo1');
|
||||
|
||||
export = {
|
||||
x: foo1
|
||||
}
|
||||
|
||||
// @Filename: foo3.ts
|
||||
import foo2 = require('./foo2')
|
||||
class x extends foo2.x {}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user