Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7538,9 +7538,9 @@ namespace ts {
signature.resolvedTypePredicate = getUnionTypePredicate(signature.unionSignatures) || noTypePredicate;
}
else {
const declaration = signature.declaration;
signature.resolvedTypePredicate = declaration && declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
const type = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
signature.resolvedTypePredicate = type && isTypePredicateNode(type) ?
createTypePredicateFromTypePredicateNode(type) :
noTypePredicate;
}
Debug.assert(!!signature.resolvedTypePredicate);
Expand Down
63 changes: 63 additions & 0 deletions tests/baselines/reference/returnTagTypeGuard.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=== tests/cases/conformance/jsdoc/bug25127.js ===
class Entry {
>Entry : Symbol(Entry, Decl(bug25127.js, 0, 0))

constructor() {
this.c = 1
>this.c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
>this : Symbol(Entry, Decl(bug25127.js, 0, 0))
>c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
}
/**
* @param {any} x
* @return {this is Entry}
*/
isInit(x) {
>isInit : Symbol(Entry.isInit, Decl(bug25127.js, 3, 5))
>x : Symbol(x, Decl(bug25127.js, 8, 11))

return true
}
}
class Group {
>Group : Symbol(Group, Decl(bug25127.js, 11, 1))

constructor() {
this.d = 'no'
>this.d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
>this : Symbol(Group, Decl(bug25127.js, 11, 1))
>d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
}
/**
* @param {any} x
* @return {false}
*/
isInit(x) {
>isInit : Symbol(Group.isInit, Decl(bug25127.js, 15, 5))
>x : Symbol(x, Decl(bug25127.js, 20, 11))

return false
}
}
/** @param {Entry | Group} chunk */
function f(chunk) {
>f : Symbol(f, Decl(bug25127.js, 23, 1))
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))

let x = chunk.isInit(chunk) ? chunk.c : chunk.d
>x : Symbol(x, Decl(bug25127.js, 26, 7))
>chunk.isInit : Symbol(isInit, Decl(bug25127.js, 3, 5), Decl(bug25127.js, 15, 5))
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
>isInit : Symbol(isInit, Decl(bug25127.js, 3, 5), Decl(bug25127.js, 15, 5))
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
>chunk.c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
>c : Symbol(Entry.c, Decl(bug25127.js, 1, 19))
>chunk.d : Symbol(Group.d, Decl(bug25127.js, 13, 19))
>chunk : Symbol(chunk, Decl(bug25127.js, 25, 11))
>d : Symbol(Group.d, Decl(bug25127.js, 13, 19))

return x
>x : Symbol(x, Decl(bug25127.js, 26, 7))
}

71 changes: 71 additions & 0 deletions tests/baselines/reference/returnTagTypeGuard.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
=== tests/cases/conformance/jsdoc/bug25127.js ===
class Entry {
>Entry : Entry

constructor() {
this.c = 1
>this.c = 1 : 1
>this.c : number
>this : this
>c : number
>1 : 1
}
/**
* @param {any} x
* @return {this is Entry}
*/
isInit(x) {
>isInit : (x: any) => this is Entry
>x : any

return true
>true : true
}
}
class Group {
>Group : Group

constructor() {
this.d = 'no'
>this.d = 'no' : "no"
>this.d : string
>this : this
>d : string
>'no' : "no"
}
/**
* @param {any} x
* @return {false}
*/
isInit(x) {
>isInit : (x: any) => false
>x : any

return false
>false : false
}
}
/** @param {Entry | Group} chunk */
function f(chunk) {
>f : (chunk: Entry | Group) => string | number
>chunk : Entry | Group

let x = chunk.isInit(chunk) ? chunk.c : chunk.d
>x : string | number
>chunk.isInit(chunk) ? chunk.c : chunk.d : string | number
>chunk.isInit(chunk) : boolean
>chunk.isInit : ((x: any) => this is Entry) | ((x: any) => false)
>chunk : Entry | Group
>isInit : ((x: any) => this is Entry) | ((x: any) => false)
>chunk : Entry | Group
>chunk.c : number
>chunk : Entry
>c : number
>chunk.d : string
>chunk : Group
>d : string

return x
>x : string | number
}

34 changes: 34 additions & 0 deletions tests/cases/conformance/jsdoc/returnTagTypeGuard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @lib: esnext
// @Filename: bug25127.js
class Entry {
constructor() {
this.c = 1
}
/**
* @param {any} x
* @return {this is Entry}
*/
isInit(x) {
return true
}
}
class Group {
constructor() {
this.d = 'no'
}
/**
* @param {any} x
* @return {false}
*/
isInit(x) {
return false
}
}
/** @param {Entry | Group} chunk */
function f(chunk) {
let x = chunk.isInit(chunk) ? chunk.c : chunk.d
return x
}