Skip to content

Mapped types not instantiated when defined in JSDoc #38572

Closed
@ilogico

Description

@ilogico

TypeScript Version: 3.9.2, 3.8.3, next

Search Terms: mapped types jsdoc

Code

/**
 * @template T
 * @param {T} a
 * @param {{[K in keyof T]: (value: T[K]) => void }} b
 */
function f(a, b) {
}

f({ x: 42 }, { x(param) { } });

Expected behavior:
I expected param to be of type number, like it is when the function is defined in TS.
Actual behavior:
param is of type { x: number }[K], even though K has no meaning/can't be bound in this context.

Playground Link: playground

Related Issues:

This occurs when defining the function in JS through JSDoc, even when used in TS.
When defined in TS, it works in JS as well.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions