-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc9b53a
commit a5c44a3
Showing
125 changed files
with
5,405 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [asOperator1.ts] | ||
var as = 43; | ||
var x = undefined as number; | ||
var y = (null as string).length; | ||
var z = Date as any as string; | ||
|
||
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' | ||
var j = 32 as number|string; | ||
j = ''; | ||
|
||
|
||
//// [asOperator1.js] | ||
var as = 43; | ||
var x = undefined; | ||
var y = null.length; | ||
var z = Date; | ||
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' | ||
var j = 32; | ||
j = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperator1.ts === | ||
var as = 43; | ||
>as : Symbol(as, Decl(asOperator1.ts, 0, 3)) | ||
|
||
var x = undefined as number; | ||
>x : Symbol(x, Decl(asOperator1.ts, 1, 3)) | ||
>undefined : Symbol(undefined) | ||
|
||
var y = (null as string).length; | ||
>y : Symbol(y, Decl(asOperator1.ts, 2, 3)) | ||
>(null as string).length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) | ||
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) | ||
|
||
var z = Date as any as string; | ||
>z : Symbol(z, Decl(asOperator1.ts, 3, 3)) | ||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) | ||
|
||
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' | ||
var j = 32 as number|string; | ||
>j : Symbol(j, Decl(asOperator1.ts, 6, 3)) | ||
|
||
j = ''; | ||
>j : Symbol(j, Decl(asOperator1.ts, 6, 3)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperator1.ts === | ||
var as = 43; | ||
>as : number | ||
>43 : number | ||
|
||
var x = undefined as number; | ||
>x : number | ||
>undefined as number : number | ||
>undefined : undefined | ||
|
||
var y = (null as string).length; | ||
>y : number | ||
>(null as string).length : number | ||
>(null as string) : string | ||
>null as string : string | ||
>null : null | ||
>length : number | ||
|
||
var z = Date as any as string; | ||
>z : string | ||
>Date as any as string : string | ||
>Date as any : any | ||
>Date : DateConstructor | ||
|
||
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' | ||
var j = 32 as number|string; | ||
>j : string | number | ||
>32 as number|string : string | number | ||
>32 : number | ||
|
||
j = ''; | ||
>j = '' : string | ||
>j : string | number | ||
>'' : string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2352: Neither type 'number' nor type 'string' is assignable to the other. | ||
|
||
|
||
==== tests/cases/conformance/expressions/asOperator/asOperator2.ts (1 errors) ==== | ||
var x = 23 as string; | ||
~~~~~~~~~~~~ | ||
!!! error TS2352: Neither type 'number' nor type 'string' is assignable to the other. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//// [asOperator2.ts] | ||
var x = 23 as string; | ||
|
||
|
||
//// [asOperator2.js] | ||
var x = 23; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [asOperator3.ts] | ||
declare function tag(...x: any[]): any; | ||
|
||
var a = `${123 + 456 as number}`; | ||
var b = `leading ${123 + 456 as number}`; | ||
var c = `${123 + 456 as number} trailing`; | ||
var d = `Hello ${123} World` as string; | ||
var e = `Hello` as string; | ||
var f = 1 + `${1} end of string` as string; | ||
var g = tag `Hello ${123} World` as string; | ||
var h = tag `Hello` as string; | ||
|
||
//// [asOperator3.js] | ||
var a = "" + 123 + 456; | ||
var b = "leading " + 123 + 456; | ||
var c = 123 + 456 + " trailing"; | ||
var d = ("Hello " + 123 + " World"); | ||
var e = "Hello"; | ||
var f = 1 + (1 + " end of string"); | ||
var g = (_a = ["Hello ", " World"], _a.raw = ["Hello ", " World"], tag(_a, 123)); | ||
var h = (_b = ["Hello"], _b.raw = ["Hello"], tag(_b)); | ||
var _a, _b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperator3.ts === | ||
declare function tag(...x: any[]): any; | ||
>tag : Symbol(tag, Decl(asOperator3.ts, 0, 0)) | ||
>x : Symbol(x, Decl(asOperator3.ts, 0, 21)) | ||
|
||
var a = `${123 + 456 as number}`; | ||
>a : Symbol(a, Decl(asOperator3.ts, 2, 3)) | ||
|
||
var b = `leading ${123 + 456 as number}`; | ||
>b : Symbol(b, Decl(asOperator3.ts, 3, 3)) | ||
|
||
var c = `${123 + 456 as number} trailing`; | ||
>c : Symbol(c, Decl(asOperator3.ts, 4, 3)) | ||
|
||
var d = `Hello ${123} World` as string; | ||
>d : Symbol(d, Decl(asOperator3.ts, 5, 3)) | ||
|
||
var e = `Hello` as string; | ||
>e : Symbol(e, Decl(asOperator3.ts, 6, 3)) | ||
|
||
var f = 1 + `${1} end of string` as string; | ||
>f : Symbol(f, Decl(asOperator3.ts, 7, 3)) | ||
|
||
var g = tag `Hello ${123} World` as string; | ||
>g : Symbol(g, Decl(asOperator3.ts, 8, 3)) | ||
>tag : Symbol(tag, Decl(asOperator3.ts, 0, 0)) | ||
|
||
var h = tag `Hello` as string; | ||
>h : Symbol(h, Decl(asOperator3.ts, 9, 3)) | ||
>tag : Symbol(tag, Decl(asOperator3.ts, 0, 0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperator3.ts === | ||
declare function tag(...x: any[]): any; | ||
>tag : (...x: any[]) => any | ||
>x : any[] | ||
|
||
var a = `${123 + 456 as number}`; | ||
>a : string | ||
>`${123 + 456 as number}` : string | ||
>123 + 456 as number : number | ||
>123 + 456 : number | ||
>123 : number | ||
>456 : number | ||
|
||
var b = `leading ${123 + 456 as number}`; | ||
>b : string | ||
>`leading ${123 + 456 as number}` : string | ||
>123 + 456 as number : number | ||
>123 + 456 : number | ||
>123 : number | ||
>456 : number | ||
|
||
var c = `${123 + 456 as number} trailing`; | ||
>c : string | ||
>`${123 + 456 as number} trailing` : string | ||
>123 + 456 as number : number | ||
>123 + 456 : number | ||
>123 : number | ||
>456 : number | ||
|
||
var d = `Hello ${123} World` as string; | ||
>d : string | ||
>`Hello ${123} World` as string : string | ||
>`Hello ${123} World` : string | ||
>123 : number | ||
|
||
var e = `Hello` as string; | ||
>e : string | ||
>`Hello` as string : string | ||
>`Hello` : string | ||
|
||
var f = 1 + `${1} end of string` as string; | ||
>f : string | ||
>1 + `${1} end of string` as string : string | ||
>1 + `${1} end of string` : string | ||
>1 : number | ||
>`${1} end of string` : string | ||
>1 : number | ||
|
||
var g = tag `Hello ${123} World` as string; | ||
>g : string | ||
>tag `Hello ${123} World` as string : string | ||
>tag `Hello ${123} World` : any | ||
>tag : (...x: any[]) => any | ||
>`Hello ${123} World` : string | ||
>123 : number | ||
|
||
var h = tag `Hello` as string; | ||
>h : string | ||
>tag `Hello` as string : string | ||
>tag `Hello` : any | ||
>tag : (...x: any[]) => any | ||
>`Hello` : string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [asOperatorASI.ts] | ||
class Foo { } | ||
declare function as(...args: any[]); | ||
|
||
// Example 1 | ||
var x = 10 | ||
as `Hello world`; // should not error | ||
|
||
// Example 2 | ||
var y = 20 | ||
as(Foo); // should emit | ||
|
||
|
||
//// [asOperatorASI.js] | ||
var Foo = (function () { | ||
function Foo() { | ||
} | ||
return Foo; | ||
})(); | ||
// Example 1 | ||
var x = 10; | ||
(_a = ["Hello world"], _a.raw = ["Hello world"], as(_a)); // should not error | ||
// Example 2 | ||
var y = 20; | ||
as(Foo); // should emit | ||
var _a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperatorASI.ts === | ||
class Foo { } | ||
>Foo : Symbol(Foo, Decl(asOperatorASI.ts, 0, 0)) | ||
|
||
declare function as(...args: any[]); | ||
>as : Symbol(as, Decl(asOperatorASI.ts, 0, 13)) | ||
>args : Symbol(args, Decl(asOperatorASI.ts, 1, 20)) | ||
|
||
// Example 1 | ||
var x = 10 | ||
>x : Symbol(x, Decl(asOperatorASI.ts, 4, 3)) | ||
|
||
as `Hello world`; // should not error | ||
>as : Symbol(as, Decl(asOperatorASI.ts, 0, 13)) | ||
|
||
// Example 2 | ||
var y = 20 | ||
>y : Symbol(y, Decl(asOperatorASI.ts, 8, 3)) | ||
|
||
as(Foo); // should emit | ||
>as : Symbol(as, Decl(asOperatorASI.ts, 0, 13)) | ||
>Foo : Symbol(Foo, Decl(asOperatorASI.ts, 0, 0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
=== tests/cases/conformance/expressions/asOperator/asOperatorASI.ts === | ||
class Foo { } | ||
>Foo : Foo | ||
|
||
declare function as(...args: any[]); | ||
>as : (...args: any[]) => any | ||
>args : any[] | ||
|
||
// Example 1 | ||
var x = 10 | ||
>x : number | ||
>10 : number | ||
|
||
as `Hello world`; // should not error | ||
>as `Hello world` : any | ||
>as : (...args: any[]) => any | ||
>`Hello world` : string | ||
|
||
// Example 2 | ||
var y = 20 | ||
>y : number | ||
>20 : number | ||
|
||
as(Foo); // should emit | ||
>as(Foo) : any | ||
>as : (...args: any[]) => any | ||
>Foo : typeof Foo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tests/cases/conformance/expressions/asOperator/asOperatorAmbiguity.ts(7,14): error TS2339: Property 'm' does not exist on type 'A<B>'. | ||
|
||
|
||
==== tests/cases/conformance/expressions/asOperator/asOperatorAmbiguity.ts (1 errors) ==== | ||
interface A<T> { x: T; } | ||
interface B { m: string; } | ||
|
||
// Make sure this is a type assertion to an array type, and not nested comparison operators. | ||
var x: any; | ||
var y = x as A<B>[]; | ||
var z = y[0].m; // z should be string | ||
~ | ||
!!! error TS2339: Property 'm' does not exist on type 'A<B>'. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//// [asOperatorAmbiguity.ts] | ||
interface A<T> { x: T; } | ||
interface B { m: string; } | ||
|
||
// Make sure this is a type assertion to an array type, and not nested comparison operators. | ||
var x: any; | ||
var y = x as A<B>[]; | ||
var z = y[0].m; // z should be string | ||
|
||
|
||
|
||
//// [asOperatorAmbiguity.js] | ||
// Make sure this is a type assertion to an array type, and not nested comparison operators. | ||
var x; | ||
var y = x; | ||
var z = y[0].m; // z should be string |
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/asOperatorContextualType.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2352: Neither type '(v: number) => number' nor type '(x: number) => string' is assignable to the other. | ||
Type 'number' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts (1 errors) ==== | ||
// should error | ||
var x = (v => v) as (x: number) => string; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2352: Neither type '(v: number) => number' nor type '(x: number) => string' is assignable to the other. | ||
!!! error TS2352: Type 'number' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//// [asOperatorContextualType.ts] | ||
// should error | ||
var x = (v => v) as (x: number) => string; | ||
|
||
//// [asOperatorContextualType.js] | ||
// should error | ||
var x = (function (v) { return v; }); |
Oops, something went wrong.