support jsdoc
This commit is contained in:
Родитель
827962fab3
Коммит
4e773730b7
|
@ -45777,12 +45777,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
const constraint = getConstraintOfTypeParameter(typeParam);
|
||||
if (!constraint || !(constraint.flags & TypeFlags.Union)) continue;
|
||||
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
||||
const container = typeParam.symbol.declarations[0].parent;
|
||||
const declaration = typeParam.symbol.declarations[0];
|
||||
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
||||
if (!isFunctionLike(container)) continue;
|
||||
let reference: Identifier | undefined;
|
||||
let hasInvalidReference = false;
|
||||
for (const paramDecl of container.parameters) {
|
||||
const typeNode = paramDecl.type;
|
||||
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
||||
if (!typeNode) continue;
|
||||
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
||||
let candidateReference;
|
||||
|
@ -45815,7 +45816,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
// - if the parameter is optional, then `T`'s constraint must allow for undefined
|
||||
function getValidParameterReference(paramDecl: ParameterDeclaration, constraint: Type): Identifier | undefined {
|
||||
if (!isIdentifier(paramDecl.name)) return;
|
||||
if (paramDecl.questionToken && !containsUndefinedType(constraint)) return;
|
||||
const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
||||
if (isOptional && !containsUndefinedType(constraint)) return;
|
||||
return paramDecl.name;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,3 +32,16 @@ function source(type = "javascript") {
|
|||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {boolean} T
|
||||
* @param {T} b
|
||||
* @returns {T extends true ? 1 : T extends false ? 2 : never}
|
||||
*/
|
||||
function simple(b) {
|
||||
>simple : Symbol(simple, Decl(file.js, 13, 1))
|
||||
>b : Symbol(b, Decl(file.js, 20, 16))
|
||||
|
||||
return b ? 1 : 2;
|
||||
>b : Symbol(b, Decl(file.js, 20, 16))
|
||||
}
|
||||
|
|
|
@ -63,3 +63,25 @@ function source(type = "javascript") {
|
|||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {boolean} T
|
||||
* @param {T} b
|
||||
* @returns {T extends true ? 1 : T extends false ? 2 : never}
|
||||
*/
|
||||
function simple(b) {
|
||||
>simple : <T extends boolean>(b: T) => T extends true ? 1 : T extends false ? 2 : never
|
||||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
|
||||
>b : T
|
||||
> : ^
|
||||
|
||||
return b ? 1 : 2;
|
||||
>b ? 1 : 2 : 2 | 1
|
||||
> : ^^^^^
|
||||
>b : T
|
||||
> : ^
|
||||
>1 : 1
|
||||
> : ^
|
||||
>2 : 2
|
||||
> : ^
|
||||
}
|
||||
|
|
|
@ -17,4 +17,13 @@ function source(type = "javascript") {
|
|||
? sources.get(type)
|
||||
: sources.get("some other thing")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {boolean} T
|
||||
* @param {T} b
|
||||
* @returns {T extends true ? 1 : T extends false ? 2 : never}
|
||||
*/
|
||||
function simple(b) {
|
||||
return b ? 1 : 2;
|
||||
}
|
Загрузка…
Ссылка в новой задаче