-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generationFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 3.1.0-dev.20180808
Search Terms: jsdoc type guard
Declaring a function as a type guard does not seem to work in JS.
any can be replaced with unknown but that doesn't change anything. The following example is trivial yet shows the issue:
Code
// filename: index.js
// @ts-check
/**
* @param {any} value
* @return {value is boolean}
*/
function isBoolean(value) {
return typeof value === "boolean";
}
// Errors here:
// @return {value is boolean}
// ~~ "}" expected (sometimes)
// ~~~~~ the name "value" was not found
/** @param {any} val */
function foo(val) {
if (isBoolean(val)) {
val; // still has type `any`
}
}Expected behavior:
- No error at the
@returnstag - inside the if-branch,
valis of typeboolean
Related Issues: #25127
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generationFixedA PR has been merged for this issueA PR has been merged for this issue