Skip to content

Commit a7af92e

Browse files
authored
check return tag in getTypePredicateOfSignature (microsoft#25130)
1 parent 7a73c89 commit a7af92e

File tree

4 files changed

+171
-3
lines changed

4 files changed

+171
-3
lines changed

src/compiler/checker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7546,9 +7546,9 @@ namespace ts {
75467546
signature.resolvedTypePredicate = getUnionTypePredicate(signature.unionSignatures) || noTypePredicate;
75477547
}
75487548
else {
7549-
const declaration = signature.declaration;
7550-
signature.resolvedTypePredicate = declaration && declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
7551-
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
7549+
const type = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
7550+
signature.resolvedTypePredicate = type && isTypePredicateNode(type) ?
7551+
createTypePredicateFromTypePredicateNode(type) :
75527552
noTypePredicate;
75537553
}
75547554
Debug.assert(!!signature.resolvedTypePredicate);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=== tests/cases/conformance/jsdoc/bug25127.js ===
2+
class Entry {
3+
>Entry : Symbol(Entry, Decl(bug25127.js, 0, 0))
4+
5+
constructor() {
6+
this.c = 1
7+
>this.c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
8+
>this : Symbol(Entry, Decl(bug25127.js, 0, 0))
9+
>c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
10+
}
11+
/**
12+
* @param {any} x
13+
* @return {this is Entry}
14+
*/
15+
isInit(x) {
16+
>isInit : Symbol(Entry.isInit, Decl(bug25127.js, 3, 5))
17+
>x : Symbol(x, Decl(bug25127.js, 8, 11))
18+
19+
return true
20+
}
21+
}
22+
class Group {
23+
>Group : Symbol(Group, Decl(bug25127.js, 11, 1))
24+
25+
constructor() {
26+
this.d = 'no'
27+
>this.d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
28+
>this : Symbol(Group, Decl(bug25127.js, 11, 1))
29+
>d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
30+
}
31+
/**
32+
* @param {any} x
33+
* @return {false}
34+
*/
35+
isInit(x) {
36+
>isInit : Symbol(Group.isInit, Decl(bug25127.js, 15, 5))
37+
>x : Symbol(x, Decl(bug25127.js, 20, 11))
38+
39+
return false
40+
}
41+
}
42+
/** @param {Entry | Group} chunk */
43+
function f(chunk) {
44+
>f : Symbol(f, Decl(bug25127.js, 23, 1))
45+
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
46+
47+
let x = chunk.isInit(chunk) ? chunk.c : chunk.d
48+
>x : Symbol(x, Decl(bug25127.js, 26, 7))
49+
>chunk.isInit : Symbol(isInit, Decl(bug25127.js, 3, 5), Decl(bug25127.js, 15, 5))
50+
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
51+
>isInit : Symbol(isInit, Decl(bug25127.js, 3, 5), Decl(bug25127.js, 15, 5))
52+
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
53+
>chunk.c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
54+
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
55+
>c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
56+
>chunk.d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
57+
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
58+
>d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
59+
60+
return x
61+
>x : Symbol(x, Decl(bug25127.js, 26, 7))
62+
}
63+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
=== tests/cases/conformance/jsdoc/bug25127.js ===
2+
class Entry {
3+
>Entry : Entry
4+
5+
constructor() {
6+
this.c = 1
7+
>this.c = 1 : 1
8+
>this.c : number
9+
>this : this
10+
>c : number
11+
>1 : 1
12+
}
13+
/**
14+
* @param {any} x
15+
* @return {this is Entry}
16+
*/
17+
isInit(x) {
18+
>isInit : (x: any) => this is Entry
19+
>x : any
20+
21+
return true
22+
>true : true
23+
}
24+
}
25+
class Group {
26+
>Group : Group
27+
28+
constructor() {
29+
this.d = 'no'
30+
>this.d = 'no' : "no"
31+
>this.d : string
32+
>this : this
33+
>d : string
34+
>'no' : "no"
35+
}
36+
/**
37+
* @param {any} x
38+
* @return {false}
39+
*/
40+
isInit(x) {
41+
>isInit : (x: any) => false
42+
>x : any
43+
44+
return false
45+
>false : false
46+
}
47+
}
48+
/** @param {Entry | Group} chunk */
49+
function f(chunk) {
50+
>f : (chunk: Entry | Group) => string | number
51+
>chunk : Entry | Group
52+
53+
let x = chunk.isInit(chunk) ? chunk.c : chunk.d
54+
>x : string | number
55+
>chunk.isInit(chunk) ? chunk.c : chunk.d : string | number
56+
>chunk.isInit(chunk) : boolean
57+
>chunk.isInit : ((x: any) => this is Entry) | ((x: any) => false)
58+
>chunk : Entry | Group
59+
>isInit : ((x: any) => this is Entry) | ((x: any) => false)
60+
>chunk : Entry | Group
61+
>chunk.c : number
62+
>chunk : Entry
63+
>c : number
64+
>chunk.d : string
65+
>chunk : Group
66+
>d : string
67+
68+
return x
69+
>x : string | number
70+
}
71+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @lib: esnext
5+
// @Filename: bug25127.js
6+
class Entry {
7+
constructor() {
8+
this.c = 1
9+
}
10+
/**
11+
* @param {any} x
12+
* @return {this is Entry}
13+
*/
14+
isInit(x) {
15+
return true
16+
}
17+
}
18+
class Group {
19+
constructor() {
20+
this.d = 'no'
21+
}
22+
/**
23+
* @param {any} x
24+
* @return {false}
25+
*/
26+
isInit(x) {
27+
return false
28+
}
29+
}
30+
/** @param {Entry | Group} chunk */
31+
function f(chunk) {
32+
let x = chunk.isInit(chunk) ? chunk.c : chunk.d
33+
return x
34+
}

0 commit comments

Comments
 (0)