question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Design Policy] Consider JSDoc feature parity with Typescript

See original GitHub issue

Search Terms

jsdoc parity, jsdoc equivalence, jsdoc

Suggestion

The JSDoc mode of TypeScript is very useful in cases where a build step (esp for node libraries for example) isn’t desired or when other constraints prevent not writing in JS. However it can be annoying when trying to implement something that can’t be expressed in JSDoc mode due to requiring Typescript syntax.

As such I would like to propose that TypeScript ensures that anything that can be written inside a .ts file can be expressed (in at least some way) within a pure javascript + jsdoc file.

In order to get an idea of the current scope needed for feature parity this is a list of issues and features that break parity between the two modes (if any are missing just say and I’ll add to the list):

  • [Bug?] No way to express the object type
    • Currently in JSDoc /** @type {object} */ is equivalent to /** @type {any} */, there doesn’t seem to be any way to represent const x: object purely in JS + JSDoc, this seems like a bug. Fixed
  • interface
  • abstract class
  • protected/private members Fixed
  • function overloading
  • ~defaults for generics~
  • declare syntax in it’s various forms and declaration merging
    • declare global { ... }
    • declare module "moduleName"
    • declare class Foo
    • declare interface
    • declare namespace
  • namespace
  • enum
    • /** @enum */ is not quite equivalent
  • ~as const~ v4.5
  • non-null assertion expr!

Checklist

My suggestion meets these guidelines:

  • [✓] This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • [✓] This wouldn’t change the runtime behavior of existing JavaScript code
  • [✓] This could be implemented without emitting different JS based on the types of the expressions
  • [✓] This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [✓] This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:22
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
weswighamcommented, Apr 18, 2019

@AlCalzone function overloads only affect usages of the function, not parameter types within a function - this is true in TS, too. You need to actually annotate parameter types on the implementation (compatible with the overloads) to get checking in the function body.

1reaction
ExE-Bosscommented, Apr 4, 2019

Function overloading can be done using:

/** @type {((name: string) => Buffer) & ((name: string, encoding: string) => string))} */
const readFile = (name, encoding = null) => { … }

I discovered this purely by accident.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDoc Reference - TypeScript: Documentation
The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.
Read more >
JSDoc or TypeScript? : r/vuejs - Reddit
I do like @param or @return or @description in a function header comment if I do need to explain more. I do tend...
Read more >
eslint-plugin-jsdoc - npm
Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also has options to lint the default values of optional @param / @arg...
Read more >
I think this is a story that gets repeated lots of times in our world of ...
And ES6 classes were designed long before they were implemented, around the time ... It's been successful so far, though they aren't at...
Read more >
How do I configure ESLint to check for TypeScript class ...
Firstly, I should note that eslint-plugin-jsdoc 's rules are incremental. If you don't have any jsdoc block at all, you first need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found