diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc17e30e0e0..89c799db46d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1234,7 +1234,7 @@ namespace ts { lastLocation.kind === SyntaxKind.Parameter || ( lastLocation === (location).type && - result.valueDeclaration.kind === SyntaxKind.Parameter + !!findAncestor(result.valueDeclaration, isParameter) ); } } diff --git a/tests/baselines/reference/functionReturnTypeQuery.js b/tests/baselines/reference/functionReturnTypeQuery.js new file mode 100644 index 00000000000..ee87f2bae21 --- /dev/null +++ b/tests/baselines/reference/functionReturnTypeQuery.js @@ -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] diff --git a/tests/baselines/reference/functionReturnTypeQuery.symbols b/tests/baselines/reference/functionReturnTypeQuery.symbols new file mode 100644 index 00000000000..1e439d6364b --- /dev/null +++ b/tests/baselines/reference/functionReturnTypeQuery.symbols @@ -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)) + diff --git a/tests/baselines/reference/functionReturnTypeQuery.types b/tests/baselines/reference/functionReturnTypeQuery.types new file mode 100644 index 00000000000..ac8a1df3894 --- /dev/null +++ b/tests/baselines/reference/functionReturnTypeQuery.types @@ -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 + diff --git a/tests/baselines/reference/typeGuardFunctionErrors.symbols b/tests/baselines/reference/typeGuardFunctionErrors.symbols index 841e986a95d..b51e84c754f 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.symbols +++ b/tests/baselines/reference/typeGuardFunctionErrors.symbols @@ -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; diff --git a/tests/baselines/reference/typeGuardFunctionErrors.types b/tests/baselines/reference/typeGuardFunctionErrors.types index 96d441d8b8d..472e81bae00 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.types +++ b/tests/baselines/reference/typeGuardFunctionErrors.types @@ -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; diff --git a/tests/cases/compiler/functionReturnTypeQuery.ts b/tests/cases/compiler/functionReturnTypeQuery.ts new file mode 100644 index 00000000000..2d644a2cc3d --- /dev/null +++ b/tests/cases/compiler/functionReturnTypeQuery.ts @@ -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; \ No newline at end of file