Skip to content

Commit

Permalink
fix type lookup rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Mar 27, 2018
1 parent dcbc478 commit 9b7e5e2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ namespace ts {
lastLocation.kind === SyntaxKind.Parameter ||
(
lastLocation === (<FunctionLikeDeclaration>location).type &&
result.valueDeclaration.kind === SyntaxKind.Parameter
!!findAncestor(result.valueDeclaration, isParameter)
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/functionReturnTypeQuery.js
Original file line number Diff line number Diff line change
@@ -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]
19 changes: 19 additions & 0 deletions tests/baselines/reference/functionReturnTypeQuery.symbols
Original file line number Diff line number Diff line change
@@ -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))

19 changes: 19 additions & 0 deletions tests/baselines/reference/functionReturnTypeQuery.types
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions tests/baselines/reference/typeGuardFunctionErrors.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/typeGuardFunctionErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/compiler/functionReturnTypeQuery.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9b7e5e2

Please sign in to comment.