4 ms·
I never use the callback tag, I tend to just do: /** @param {(x: X) => Y} f */ Works fine. If you can let me know a RORO pattern you had trouble typing I mi
by lacampbell 7y ago
I never use the callback tag, I tend to just do:
/** @param {(x: X) => Y} f */
Works fine. If you can let me know a RORO pattern you had trouble typing I might be able to help.
- lhorie 7y agoThe problem with @param is that it requires a binding name I ended up doing this instead: /** @typedef {{x: string}} FooArgs @typedef {{y: string}} FooResult @type {function(FooArgs): FooResult} */ export const foo = ({x}) => ({y: x}); It works, but the double curly feels a bit clunky. Compare to Flow: /*:: type FooArgs = {x: string}; type FooResult = {y: string}; type Foo = (FooArgs) => FooResult; */ export const foo /*: Foo */ = ({x}) => ({y: x}); In Flow, the declaration ends up looking essentially the same between comment syntax and non-comment syntax. With TS, RORO ends up looking like Flow (but with weirder indentation on large enough structs), whereas I'd prefer to express regular functions in terms of @callback, @param and @returns since that's more in line w/ the spirit of jsdoc. Not a huge deal, in any case, considering the upsides of comment syntax.
- lacampbell 7y agoindex.d.ts: type FooArgs = {x: string} type FooResult = {y: string} type Foo = (_: FooArgs) => FooResult index.js: /// <reference path="index.d.ts"/> /** @type {Foo} */ export const foo = ({x}) => ({y: x}) Works as well
- deleted 7y ago[deleted]
- lhorie 7y agoGood point!