mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-10 00:20:22 -06:00
Treat functions with @type tags on parameters as typed in JS files (#61177)
This commit is contained in:
parent
83dc0bb2ed
commit
eef7c14ef1
@ -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) {
|
||||
|
||||
31
tests/baselines/reference/jsdocTypeTagOnParameter1.symbols
Normal file
31
tests/baselines/reference/jsdocTypeTagOnParameter1.symbols
Normal 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))
|
||||
|
||||
55
tests/baselines/reference/jsdocTypeTagOnParameter1.types
Normal file
55
tests/baselines/reference/jsdocTypeTagOnParameter1.types
Normal 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
|
||||
> : ^
|
||||
|
||||
21
tests/cases/conformance/jsdoc/jsdocTypeTagOnParameter1.ts
Normal file
21
tests/cases/conformance/jsdoc/jsdocTypeTagOnParameter1.ts
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user