Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Never face facts; if you do, you'll never get up in the morning." -- Marlo Thomas


devel / comp.lang.javascript / Re: TypeScript JSDoc generic member function

SubjectAuthor
* TypeScript JSDoc generic member functionJulio Di Egidio
+- Re: TypeScript JSDoc generic member functionJohn Harris
`- Re: TypeScript JSDoc generic member functionJulio Di Egidio

1
TypeScript JSDoc generic member function

<uhbl9k$u0u5$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18282&group=comp.lang.javascript#18282

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.javascript
Subject: TypeScript JSDoc generic member function
Date: Wed, 25 Oct 2023 20:03:30 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <uhbl9k$u0u5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 25 Oct 2023 18:03:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9803957ef926f31ca3bad958bac8a082";
logging-data="984005"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aHwL2OaM4be7j/OdjdqFRy+myLVEgGj0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HGO28rgflzuz9/tFFe0dRIDI5Gk=
Content-Language: en-GB
 by: Julio Di Egidio - Wed, 25 Oct 2023 18:03 UTC

I cannot seem to find a way to tell TypeScript with JSDoc that a
member function of some object/interface takes a type parameter.

Here is a minimal example illustrating the problem:

```js
/**
* @template {unknown} T
* @callback IGet
* @param {string} key
* @returns {T | undefined}
*/

/**
* @typedef IGetter
* @type {object}
* _@template {unknown} T // how to write this?
* @property {IGet<T>} get
*/
```

Error: Cannot find name 'T'.

That of course can be done in TypeScript, but how to do it with
JSDoc? Is it at all possible?

Link to TypeScript playground:
<https://www.typescriptlang.org/play?strictNullChecks=true&noUncheckedIndexedAccess=true&allowUnusedLabels=true&noUnusedLocals=true&noUnusedParameters=true&removeComments=true&target=1&module=1&pretty=true&isolatedModules=true&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&keyofStringsOnly=true&filetype=js#code/PQKhCgAIUgBAXApgWwA4BsCGTIG8CuAdgNaED2A7oQL6QAqUMsAxpuugEabPGQCSAcUTxGcVJgBOmZHgDO8CQEtCAc1rFEAT1GwJw-BMKy8dSAB9IRACaIAZssRXqjYOHCgI0OPE2pHd-iF4JAkdHz88Mg4AK0RmeGdIJKSYAH0EFAxsRDwiUkoaeiTgYEgAC0pIeDJICiUceDLFWQB+HVQJMj8JHzxBYQAeOgA+WhVhF3AgA>

Julio

Re: TypeScript JSDoc generic member function

<uhdevh$1h52v$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18283&group=comp.lang.javascript#18283

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: niam@jghnorth.org.uk.invalid (John Harris)
Newsgroups: comp.lang.javascript
Subject: Re: TypeScript JSDoc generic member function
Date: Thu, 26 Oct 2023 11:28:00 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <uhdevh$1h52v$1@dont-email.me>
References: <uhbl9k$u0u5$1@dont-email.me>
Reply-To: jgharris@ic4life.net
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 26 Oct 2023 10:28:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6ac4105fc3faa08080f6993d4601fc4a";
logging-data="1610847"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XOdQxBqkE276lqh9wjSf2QHnfc/z/aiI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lDzxzyZ/NEE66AbqjZw9KFeiUIE=
In-Reply-To: <uhbl9k$u0u5$1@dont-email.me>
Content-Language: en-US
 by: John Harris - Thu, 26 Oct 2023 10:28 UTC

On 25/10/2023 19:03, Julio Di Egidio wrote:
> I cannot seem to find a way to tell TypeScript with JSDoc that a
> member function of some object/interface takes a type parameter.
>
> Here is a minimal example illustrating the problem:
>
> ```js
> /**
>  * @template {unknown} T
>  * @callback IGet
>  * @param {string} key
>  * @returns {T | undefined}
>  */
>
> /**
>  * @typedef IGetter
>  * @type {object}
>      * _@template {unknown} T  // how to write this?
>  * @property {IGet<T>} get
>  */
> ```
>
> Error: Cannot find name 'T'.
>
> That of course can be done in TypeScript, but how to do it with
> JSDoc?  Is it at all possible?
>
> Link to TypeScript playground:
> <https://www.typescriptlang.org/play?strictNullChecks=true&noUncheckedIndexedAccess=true&allowUnusedLabels=true&noUnusedLocals=true&noUnusedParameters=true&removeComments=true&target=1&module=1&pretty=true&isolatedModules=true&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&keyofStringsOnly=true&filetype=js#code/PQKhCgAIUgBAXApgWwA4BsCGTIG8CuAdgNaED2A7oQL6QAqUMsAxpuugEabPGQCSAcUTxGcVJgBOmZHgDO8CQEtCAc1rFEAT1GwJw-BMKy8dSAB9IRACaIAZssRXqjYOHCgI0OPE2pHd-iF4JAkdHz88Mg4AK0RmeGdIJKSYAH0EFAxsRDwiUkoaeiTgYEgAC0pIeDJICiUceDLFWQB+HVQJMj8JHzxBYQAeOgA+WhVhF3AgA>
>
> Julio

That's the trouble with documentation programs. Users have no control
over the program's prejudices.

John

Re: TypeScript JSDoc generic member function

<uhdst7$1l4pq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18284&group=comp.lang.javascript#18284

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.javascript
Subject: Re: TypeScript JSDoc generic member function
Date: Thu, 26 Oct 2023 16:25:41 +0200
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <uhdst7$1l4pq$1@dont-email.me>
References: <uhbl9k$u0u5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 26 Oct 2023 14:25:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2003d5720332bda623cb158c6af1073d";
logging-data="1741626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VpcqAUtCuQSSn9zCnRxiZrfpJBVd8+YQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ixizQTJJmyqnQeM5xMBkoORGJ3c=
Content-Language: en-GB
In-Reply-To: <uhbl9k$u0u5$1@dont-email.me>
 by: Julio Di Egidio - Thu, 26 Oct 2023 14:25 UTC

On 25/10/2023 20:03, Julio Di Egidio wrote:
> I cannot seem to find a way to tell TypeScript with JSDoc that a
> member function of some object/interface takes a type parameter.
>
> Here is a minimal example illustrating the problem:
>
> ```js
> /**
>  * @template {unknown} T
>  * @callback IGet
>  * @param {string} key
>  * @returns {T | undefined}
>  */
>
> /**
>  * @typedef IGetter
>  * @type {object}
>      * _@template {unknown} T  // how to write this?
>  * @property {IGet<T>} get
>  */
> ```
>
> Error: Cannot find name 'T'.
>
> That of course can be done in TypeScript, but how to do it with
> [TypeScript's] JSDoc?  Is it at all possible?

I was wrong, that cannot be done in TypeScript either...

Eventually, the only way I have found is to repeat the
declaration in-line, as in:

```js
/**
* @typedef IGetter
* @type {object}
* @property {<T extends unknown>(key: string) => (T | undefined)} get
*/
```

but I lose any chance to properly document that function, which
is simply quite a disaster: and not the only one, also the return
type gets messed up (becomes just `T`), to the point that I am
compelled to do something altogether different, i.e. have a
concrete object constructor.

File under the misery of an entire industry.

Julio

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor