Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsdoc unable to refer template from another template's constaint #43403

Closed
awerlogus opened this issue Mar 27, 2021 · 1 comment
Closed

Jsdoc unable to refer template from another template's constaint #43403

awerlogus opened this issue Mar 27, 2021 · 1 comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Milestone

Comments

@awerlogus
Copy link

awerlogus commented Mar 27, 2021

Bug Report

🔎 Search Terms jsdoc template

🕗 Version 4.3.0-dev.20210327

💻 Code

In .ts files we are able to refer template type from another template's constraint

type A<T1, T2 extends T1> = [T1, T2]

But in jsdoc it's not possible

/** 
 * @template T1
 * // Cannot find name 'T1'.ts(2304)
 * @template {T1} T2
 * 
 * @typedef {[T1, T2]} A
 */

🙁 Actual behavior

'Cannot find name' error

🙂 Expected behavior

No error

@awerlogus awerlogus changed the title Jsdoc unable to refer template from another template constaint Jsdoc unable to refer template from another template's constaint Mar 27, 2021
@ilogico
Copy link

ilogico commented Mar 28, 2021

This is very strange. It happens with typedef only, but I have different errors depending on the location of the typedef.
This one says B doesn't satisfy A.
This one works.
And this one reproduces your error.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 29, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 29, 2021
robertknight added a commit to hypothesis/client that referenced this issue Jun 2, 2021
Improve the type of the `selectors` argument to `createStoreModule` to
link it to the type of the initial state returned by the `initialState`
argument. This enables TS to check/infer that the first argument to
these functions should be of the same type that `initialState` returns.

In the process it was necessary to remove the `ModuleConfig` type and
declare the type of `createStoreModule`'s `config` argument inline.
This works around a TypeScript limitation [1]:

```
@template State
@template {SelectorMap<State>} Selectors // Unexpected error
...
@typedef ModuleConfig
```

But this works:

``
@template State
@template {SelectorMap<State>} Selectors // OK
...
function createStoreModule(...) { ... }
```

[1] microsoft/TypeScript#43403
robertknight added a commit to hypothesis/client that referenced this issue Jun 7, 2021
Improve the type of the `selectors` argument to `createStoreModule` to
link it to the type of the initial state returned by the `initialState`
argument. This enables TS to check/infer that the first argument to
these functions should be of the same type that `initialState` returns.

In the process it was necessary to remove the `ModuleConfig` type and
declare the type of `createStoreModule`'s `config` argument inline.
This works around a TypeScript limitation [1]:

```
@template State
@template {SelectorMap<State>} Selectors // Unexpected error
...
@typedef ModuleConfig
```

But this works:

``
@template State
@template {SelectorMap<State>} Selectors // OK
...
function createStoreModule(...) { ... }
```

[1] microsoft/TypeScript#43403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants