Treat functions with @type tags on parameters as typed in JS files (#61177)

This commit is contained in:
Mateusz Burzyński 2025-04-15 00:35:20 +02:00 committed by GitHub
parent 83dc0bb2ed
commit eef7c14ef1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 108 additions and 0 deletions

View File

@ -15507,6 +15507,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isInJSFile(declaration) &&
isValueSignatureDeclaration(declaration) &&
!hasJSDocParameterTags(declaration) &&
!some(declaration.parameters, p => !!getJSDocType(p)) &&
!getJSDocType(declaration) &&
!getContextualSignatureForFunctionLikeDeclaration(declaration);
if (isUntypedSignatureInJSFile) {

View File

@ -0,0 +1,31 @@
//// [tests/cases/conformance/jsdoc/jsdocTypeTagOnParameter1.ts] ////
=== /index.js ===
function repeat(
>repeat : Symbol(repeat, Decl(index.js, 0, 0))
/** @type {string} */ message,
>message : Symbol(message, Decl(index.js, 0, 16))
/** @type {number} */ times,
>times : Symbol(times, Decl(index.js, 1, 31))
) {
return Array(times).fill(message).join(` `);
>Array(times).fill(message).join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
>Array(times).fill : Symbol(Array.fill, Decl(lib.es2015.core.d.ts, --, --))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
>times : Symbol(times, Decl(index.js, 1, 31))
>fill : Symbol(Array.fill, Decl(lib.es2015.core.d.ts, --, --))
>message : Symbol(message, Decl(index.js, 0, 16))
>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
}
/** @type {Parameters<typeof repeat>[0]} */
const message = `hello`;
>message : Symbol(message, Decl(index.js, 8, 5))
/** @type {Parameters<typeof repeat>[1]} */
const times = 3;
>times : Symbol(times, Decl(index.js, 11, 5))

View File

@ -0,0 +1,55 @@
//// [tests/cases/conformance/jsdoc/jsdocTypeTagOnParameter1.ts] ////
=== /index.js ===
function repeat(
>repeat : (message: string, times: number) => string
> : ^ ^^ ^^ ^^ ^^^^^^^^^^^
/** @type {string} */ message,
>message : string
> : ^^^^^^
/** @type {number} */ times,
>times : number
> : ^^^^^^
) {
return Array(times).fill(message).join(` `);
>Array(times).fill(message).join(` `) : string
> : ^^^^^^
>Array(times).fill(message).join : (separator?: string) => string
> : ^ ^^^ ^^^^^
>Array(times).fill(message) : any[]
> : ^^^^^
>Array(times).fill : (value: any, start?: number, end?: number) => any[]
> : ^ ^^^^^^^ ^^^ ^^ ^^^ ^^^^^^^^^^
>Array(times) : any[]
> : ^^^^^
>Array : ArrayConstructor
> : ^^^^^^^^^^^^^^^^
>times : number
> : ^^^^^^
>fill : (value: any, start?: number, end?: number) => any[]
> : ^ ^^^^^^^ ^^^ ^^ ^^^ ^^^^^^^^^^
>message : string
> : ^^^^^^
>join : (separator?: string) => string
> : ^ ^^^ ^^^^^
>` ` : " "
> : ^^^
}
/** @type {Parameters<typeof repeat>[0]} */
const message = `hello`;
>message : string
> : ^^^^^^
>`hello` : "hello"
> : ^^^^^^^
/** @type {Parameters<typeof repeat>[1]} */
const times = 3;
>times : number
> : ^^^^^^
>3 : 3
> : ^

View File

@ -0,0 +1,21 @@
// @strict: true
// @lib: esnext
// @allowJS: true
// @checkJs: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/61172
// @filename: /index.js
function repeat(
/** @type {string} */ message,
/** @type {number} */ times,
) {
return Array(times).fill(message).join(` `);
}
/** @type {Parameters<typeof repeat>[0]} */
const message = `hello`;
/** @type {Parameters<typeof repeat>[1]} */
const times = 3;