Skip to content

JSDOC inconsistance casting behavior #23362

@mmis1000

Description

@mmis1000

TypeScript Version: 2.8.1

Search Terms:
jsdoc, casting

Code

utils.d.ts

declare namespace utils {
   export type PartialTypeGuard<T, U extends T> = (value: T) => value is U;
   export type TypeGuard<T> = PartialTypeGuard<any, T>;
}

test.js

// @ts-check
/// <reference path="./utils.d.ts" />

/**
 * @type {utils.TypeGuard<string>}
 */
let pass = ((a)=>typeof a === 'string');

/**
 * @type {utils.TypeGuard<string>}
 */
let fail = (a)=>typeof a === 'string';

Expected behavior:
They both throw error due to casting between item with incompatible signature without explicit casting

Actual behavior:
The first one pass for unknown reason , the second one failed as expect

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specifically

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions