Skip to content

Commit 9b7e5e2

Browse files
committed
fix type lookup rule
1 parent dcbc478 commit 9b7e5e2

7 files changed

+56
-4
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ namespace ts {
12341234
lastLocation.kind === SyntaxKind.Parameter ||
12351235
(
12361236
lastLocation === (<FunctionLikeDeclaration>location).type &&
1237-
result.valueDeclaration.kind === SyntaxKind.Parameter
1237+
!!findAncestor(result.valueDeclaration, isParameter)
12381238
);
12391239
}
12401240
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [functionReturnTypeQuery.ts]
2+
declare let foo: number;
3+
4+
declare function test1(foo: string, bar: typeof foo): typeof foo;
5+
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
6+
7+
//// [functionReturnTypeQuery.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/functionReturnTypeQuery.ts ===
2+
declare let foo: number;
3+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 0, 11))
4+
5+
declare function test1(foo: string, bar: typeof foo): typeof foo;
6+
>test1 : Symbol(test1, Decl(functionReturnTypeQuery.ts, 0, 24))
7+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
8+
>bar : Symbol(bar, Decl(functionReturnTypeQuery.ts, 2, 35))
9+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
10+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 2, 23))
11+
12+
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
13+
>test2 : Symbol(test2, Decl(functionReturnTypeQuery.ts, 2, 65))
14+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))
15+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 31))
16+
>bar : Symbol(bar, Decl(functionReturnTypeQuery.ts, 3, 44))
17+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))
18+
>foo : Symbol(foo, Decl(functionReturnTypeQuery.ts, 3, 24))
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/functionReturnTypeQuery.ts ===
2+
declare let foo: number;
3+
>foo : number
4+
5+
declare function test1(foo: string, bar: typeof foo): typeof foo;
6+
>test1 : (foo: string, bar: string) => string
7+
>foo : string
8+
>bar : string
9+
>foo : string
10+
>foo : string
11+
12+
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;
13+
>test2 : ({ foo }: { foo: string; }, bar: string) => string
14+
>foo : string
15+
>foo : string
16+
>bar : string
17+
>foo : string
18+
>foo : string
19+

tests/baselines/reference/typeGuardFunctionErrors.symbols

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ function b5({a, b, p1}, p2, p3): p1 is A {
312312
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18))
313313
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 127, 23))
314314
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 127, 27))
315+
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18))
315316
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
316317

317318
return true;
@@ -324,6 +325,7 @@ function b6([a, b, p1], p2, p3): p1 is A {
324325
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18))
325326
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 131, 23))
326327
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 131, 27))
328+
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18))
327329
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
328330

329331
return true;
@@ -337,6 +339,7 @@ function b7({a, b, c: {p1}}, p2, p3): p1 is A {
337339
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23))
338340
>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 135, 28))
339341
>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 135, 32))
342+
>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23))
340343
>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0))
341344

342345
return true;

tests/baselines/reference/typeGuardFunctionErrors.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function b5({a, b, p1}, p2, p3): p1 is A {
356356
>p1 : any
357357
>p2 : any
358358
>p3 : any
359-
>p1 : No type information available!
359+
>p1 : any
360360
>A : A
361361

362362
return true;
@@ -370,7 +370,7 @@ function b6([a, b, p1], p2, p3): p1 is A {
370370
>p1 : any
371371
>p2 : any
372372
>p3 : any
373-
>p1 : No type information available!
373+
>p1 : any
374374
>A : A
375375

376376
return true;
@@ -385,7 +385,7 @@ function b7({a, b, c: {p1}}, p2, p3): p1 is A {
385385
>p1 : any
386386
>p2 : any
387387
>p3 : any
388-
>p1 : No type information available!
388+
>p1 : any
389389
>A : A
390390

391391
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare let foo: number;
2+
3+
declare function test1(foo: string, bar: typeof foo): typeof foo;
4+
declare function test2({foo}: {foo: string}, bar: typeof foo): typeof foo;

0 commit comments

Comments
 (0)