Skip to content

Type inference with JSDoc, @template and curried functions #36201

Closed
@RedGlow

Description

@RedGlow

Issue Type: Bug

(I'm not completely sure this is the right place to report this bug, so point me to the correct place in case)

Let's take this JavaScript code:

/**
 * @template T
 * @param {T} a 
 * @returns {(b: T) => T}
 */
const curriedFunction = a => b => b;

const text1 = "hello";
const text2 = "Mattia";

const text3 = curriedFunction(text1)(text2);

The types that VSCode infers are:

const curriedFunction: <T>(a: T) => (b: T) => T
const text1: "hello"
const text2: "Mattia"
const text3: T

All types are correct expect for text3. In fact, if I look at the type instantiation for the curriedFunction call, I get this:

const curriedFunction: <string>(a: string) => (b: T) => T

Now, it seems to me that the first T instantiation is correctly bound to string, but then the return value doesn't get its T bound to the same template variable. Am I missing something, or this is the type that I should get?

const curriedFunction: <string>(a: string) => (b: string) => string

VS Code version: Code 1.41.1 (26076a4de974ead31f97692a0d32f90d735645c0, 2019-12-18T14:58:56.166Z)
OS version: Windows_NT x64 10.0.17134

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz (4 x 2904)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.83GB (17.31GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (5)
Extension Author (truncated) Version
npm-intellisense chr 1.3.0
gitlens eam 10.2.0
vscode-npm-script eg2 0.3.10
prettier-vscode esb 3.18.0
vscode-import-cost wix 2.12.0

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationDomain: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionEffort: DifficultGood luck.Fix AvailableA PR has been opened for this issueHelp WantedYou can do thischeckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions