Test:type predicate uses correct index to report errors

This commit is contained in:
Nathan Shively-Sanders 2017-08-09 15:45:28 -07:00
parent 8ae7c6c227
commit a59f77ffb4
4 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
//// [thisTypeInTypePredicate.ts]
declare function filter<S>(f: (this: void, x: any) => x is S): S[];
const numbers = filter<number>((x): x is number => 'number' == typeof x)
//// [thisTypeInTypePredicate.js]
var numbers = filter(function (x) { return 'number' == typeof x; });

View File

@ -0,0 +1,18 @@
=== tests/cases/conformance/types/thisType/thisTypeInTypePredicate.ts ===
declare function filter<S>(f: (this: void, x: any) => x is S): S[];
>filter : Symbol(filter, Decl(thisTypeInTypePredicate.ts, 0, 0))
>S : Symbol(S, Decl(thisTypeInTypePredicate.ts, 0, 24))
>f : Symbol(f, Decl(thisTypeInTypePredicate.ts, 0, 27))
>this : Symbol(this, Decl(thisTypeInTypePredicate.ts, 0, 31))
>x : Symbol(x, Decl(thisTypeInTypePredicate.ts, 0, 42))
>x : Symbol(x, Decl(thisTypeInTypePredicate.ts, 0, 42))
>S : Symbol(S, Decl(thisTypeInTypePredicate.ts, 0, 24))
>S : Symbol(S, Decl(thisTypeInTypePredicate.ts, 0, 24))
const numbers = filter<number>((x): x is number => 'number' == typeof x)
>numbers : Symbol(numbers, Decl(thisTypeInTypePredicate.ts, 1, 5))
>filter : Symbol(filter, Decl(thisTypeInTypePredicate.ts, 0, 0))
>x : Symbol(x, Decl(thisTypeInTypePredicate.ts, 1, 32))
>x : Symbol(x, Decl(thisTypeInTypePredicate.ts, 1, 32))
>x : Symbol(x, Decl(thisTypeInTypePredicate.ts, 1, 32))

View File

@ -0,0 +1,23 @@
=== tests/cases/conformance/types/thisType/thisTypeInTypePredicate.ts ===
declare function filter<S>(f: (this: void, x: any) => x is S): S[];
>filter : <S>(f: (this: void, x: any) => x is S) => S[]
>S : S
>f : (this: void, x: any) => x is S
>this : void
>x : any
>x : any
>S : S
>S : S
const numbers = filter<number>((x): x is number => 'number' == typeof x)
>numbers : number[]
>filter<number>((x): x is number => 'number' == typeof x) : number[]
>filter : <S>(f: (this: void, x: any) => x is S) => S[]
>(x): x is number => 'number' == typeof x : (this: void, x: any) => x is number
>x : any
>x : any
>'number' == typeof x : boolean
>'number' : "number"
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : any

View File

@ -0,0 +1,2 @@
declare function filter<S>(f: (this: void, x: any) => x is S): S[];
const numbers = filter<number>((x): x is number => 'number' == typeof x)