check return tag in getTypePredicateOfSignature (#25130)

This commit is contained in:
Nathan Shively-Sanders 2018-06-21 11:30:37 -07:00 committed by GitHub
parent 7a73c89c57
commit a7af92eb63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 171 additions and 3 deletions

View file

@ -7546,9 +7546,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);

View file

@ -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))
}

View file

@ -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
}

View file

@ -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
}