Merge pull request #22898 from Kingwl/fix-return-type-lookup-rule

fix type lookup rule
This commit is contained in:
Mohamed Hegazy 2018-03-27 17:01:56 -07:00 committed by GitHub
commit 4699c829de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 4 deletions

View File

@ -1234,7 +1234,7 @@ namespace ts {
lastLocation.kind === SyntaxKind.Parameter ||
(
lastLocation === (<FunctionLikeDeclaration>location).type &&
result.valueDeclaration.kind === SyntaxKind.Parameter
!!findAncestor(result.valueDeclaration, isParameter)
);
}
}

View File

@ -0,0 +1,7 @@
//// [functionReturnTypeQuery.ts]
declare let foo: number;
declare function test1(foo: string, bar: typeof foo): typeof foo;
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
//// [functionReturnTypeQuery.js]

View File

@ -0,0 +1,19 @@
=== tests/cases/compiler/functionReturnTypeQuery.ts ===
declare let foo: number;
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 0, 11))
declare function test1(foo: string, bar: typeof foo): typeof foo;
>test1 : Symbol(test1, Decl(functionReturnTypeQuery.ts, 0, 24))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
>bar : Symbol(bar, Decl(functionReturnTypeQuery.ts, 2, 35))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
>test2 : Symbol(test2, Decl(functionReturnTypeQuery.ts, 2, 65))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 31))
>bar : Symbol(bar, Decl(functionReturnTypeQuery.ts, 3, 44))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))

View File

@ -0,0 +1,19 @@
=== tests/cases/compiler/functionReturnTypeQuery.ts ===
declare let foo: number;
>foo : number
declare function test1(foo: string, bar: typeof foo): typeof foo;
>test1 : (foo: string, bar: string) => string
>foo : string
>bar : string
>foo : string
>foo : string
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
>test2 : ({ foo }: { foo: string; }, bar: string) => string
>foo : string
>foo : string
>bar : string
>foo : string
>foo : string

View File

@ -312,6 +312,7 @@ function b5({a, b, p1}, p2, p3): p1 is A {
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18))
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 127, 23))
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 127, 27))
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18))
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
return true;
@ -324,6 +325,7 @@ function b6([a, b, p1], p2, p3): p1 is A {
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18))
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 131, 23))
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 131, 27))
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18))
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
return true;
@ -337,6 +339,7 @@ function b7({a, b, c: {p1}}, p2, p3): p1 is A {
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23))
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 135, 28))
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 135, 32))
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23))
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
return true;

View File

@ -356,7 +356,7 @@ function b5({a, b, p1}, p2, p3): p1 is A {
>p1 : any
>p2 : any
>p3 : any
>p1 : No type information available!
>p1 : any
>A : A
return true;
@ -370,7 +370,7 @@ function b6([a, b, p1], p2, p3): p1 is A {
>p1 : any
>p2 : any
>p3 : any
>p1 : No type information available!
>p1 : any
>A : A
return true;
@ -385,7 +385,7 @@ function b7({a, b, c: {p1}}, p2, p3): p1 is A {
>p1 : any
>p2 : any
>p3 : any
>p1 : No type information available!
>p1 : any
>A : A
return true;

View File

@ -0,0 +1,4 @@
declare let foo: number;
declare function test1(foo: string, bar: typeof foo): typeof foo;
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;