don't skip jsdoc type assertions
This commit is contained in:
Родитель
20b79eb8c8
Коммит
3788ada9b9
|
@ -45645,7 +45645,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
const functionFlags = getFunctionFlags(container);
|
||||
const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
|
||||
if (expr) {
|
||||
const unwrappedExpr = skipParentheses(expr);
|
||||
const unwrappedExpr = skipParentheses(expr, /*excludeJSDocTypeAssertions*/ true);
|
||||
if (isConditionalExpression(unwrappedExpr)) {
|
||||
return checkConditionalReturnExpression(container, returnType, node, unwrappedExpr);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
//// [tests/cases/compiler/dependentReturnType7.ts] ////
|
||||
|
||||
=== file.js ===
|
||||
/** @type {Map<string, string>} */
|
||||
const sources = new Map();
|
||||
>sources : Symbol(sources, Decl(file.js, 1, 5))
|
||||
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
|
||||
|
||||
/**
|
||||
|
||||
* @param {string=} type the type of source that should be generated
|
||||
* @returns {String}
|
||||
*/
|
||||
function source(type = "javascript") {
|
||||
>source : Symbol(source, Decl(file.js, 1, 26))
|
||||
>type : Symbol(type, Decl(file.js, 7, 16))
|
||||
|
||||
return /** @type {String} */ (
|
||||
type
|
||||
>type : Symbol(type, Decl(file.js, 7, 16))
|
||||
|
||||
? sources.get(type)
|
||||
>sources.get : Symbol(Map.get, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>sources : Symbol(sources, Decl(file.js, 1, 5))
|
||||
>get : Symbol(Map.get, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>type : Symbol(type, Decl(file.js, 7, 16))
|
||||
|
||||
: sources.get("some other thing")
|
||||
>sources.get : Symbol(Map.get, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>sources : Symbol(sources, Decl(file.js, 1, 5))
|
||||
>get : Symbol(Map.get, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
//// [tests/cases/compiler/dependentReturnType7.ts] ////
|
||||
|
||||
=== Performance Stats ===
|
||||
Type Count: 1,000
|
||||
Instantiation count: 2,500
|
||||
|
||||
=== file.js ===
|
||||
/** @type {Map<string, string>} */
|
||||
const sources = new Map();
|
||||
>sources : Map<string, string>
|
||||
> : ^^^^^^^^^^^^^^^^^^^
|
||||
>new Map() : Map<any, any>
|
||||
> : ^^^^^^^^^^^^^
|
||||
>Map : MapConstructor
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
/**
|
||||
|
||||
* @param {string=} type the type of source that should be generated
|
||||
* @returns {String}
|
||||
*/
|
||||
function source(type = "javascript") {
|
||||
>source : (type?: string | undefined) => string
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^^^^^^^^
|
||||
>type : string | undefined
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>"javascript" : "javascript"
|
||||
> : ^^^^^^^^^^^^
|
||||
|
||||
return /** @type {String} */ (
|
||||
>( type ? sources.get(type) : sources.get("some other thing") ) : string
|
||||
> : ^^^^^^
|
||||
|
||||
type
|
||||
>type ? sources.get(type) : sources.get("some other thing") : string | undefined
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>type : string
|
||||
> : ^^^^^^
|
||||
|
||||
? sources.get(type)
|
||||
>sources.get(type) : string | undefined
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>sources.get : (key: string) => string | undefined
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>sources : Map<string, string>
|
||||
> : ^^^^^^^^^^^^^^^^^^^
|
||||
>get : (key: string) => string | undefined
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>type : string
|
||||
> : ^^^^^^
|
||||
|
||||
: sources.get("some other thing")
|
||||
>sources.get("some other thing") : string | undefined
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>sources.get : (key: string) => string | undefined
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>sources : Map<string, string>
|
||||
> : ^^^^^^^^^^^^^^^^^^^
|
||||
>get : (key: string) => string | undefined
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
>"some other thing" : "some other thing"
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// @strict: true
|
||||
// @noEmit: true
|
||||
// @target: esnext
|
||||
// @checkJs: true
|
||||
// @filename: file.js
|
||||
|
||||
/** @type {Map<string, string>} */
|
||||
const sources = new Map();
|
||||
/**
|
||||
|
||||
* @param {string=} type the type of source that should be generated
|
||||
* @returns {String}
|
||||
*/
|
||||
function source(type = "javascript") {
|
||||
return /** @type {String} */ (
|
||||
type
|
||||
? sources.get(type)
|
||||
: sources.get("some other thing")
|
||||
);
|
||||
}
|
Загрузка…
Ссылка в новой задаче