TypeScript/tests/cases/conformance/jsdoc/checkJsdocTypeTag5.ts
Nathan Shively-Sanders bd7b97ce61
Get return type from @type tag (#25580)
* Get return type from `@type` tag

This only happens in the checker, where the type is easily accessible.
The syntax-based check in getEffectiveReturnTypeNode as a fast path, and
for other uses that don't want to make a call to getTypeFromTypeNode.

Fixes #25525

* Implement PR suggestions

* Error when type tag isn't callable

* Fix lint
2018-07-12 10:49:41 -07:00

39 lines
988 B
TypeScript

// @checkJs: true
// @allowJs: true
// @noEmit: true
// @Filename: test.js
// all 6 should error on return statement/expression
/** @type {(x: number) => string} */
function h(x) { return x }
/** @type {(x: number) => string} */
var f = x => x
/** @type {(x: number) => string} */
var g = function (x) { return x }
/** @type {{ (x: number): string }} */
function i(x) { return x }
/** @type {{ (x: number): string }} */
var j = x => x
/** @type {{ (x: number): string }} */
var k = function (x) { return x }
/** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */
/** @type {Argle} */
function blargle(s) {
return 0;
}
/** @type {0 | 1 | 2} - assignment should not error */
var zeroonetwo = blargle('hi')
/** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */
/** @type {Gioconda} */
function monaLisa(sb) {
return typeof sb === 'string' ? 1 : 2;
}
/** @type {2 | 3} - overloads are not supported, so there will be an error */
var twothree = monaLisa(false);