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.

"declare module" may need quotes

See original GitHub issue

Thank you for all the work put into that great project, @englercj! I currently develop jsdoc-tsd-webpack-plugin which generates tsd-jsdoc output and better-docs output through Webpack compilation.

array-to-object-keys is an example project from me. This is the important part:

/** @module array-to-object-keys */
// Removed for simplicity
/**
 * Converts an array to an object with static keys and customizable values
 * @example
 * arrayToObjectKeys(["a", "b"])
 * // {a: null, b: null}
 * @example
 * arrayToObjectKeys(["a", "b"], "value")
 * // {a: "value", b: "value"}
 * @example
 * arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`)
 * // {a: "value for a #1", b: "value for b #2"}
 * @param {string[]} array Keys for the generated object
 * @param {valueGenerator|*} [valueGenerator=null] Optional function that sets the object values based on key and index
 * @returns {Object<string, *>} A generated object based on the array input
 */
export default (array, valueGenerator = null) => {
// Removed for simplicity
}

tsd-jsdoc generates:

/** @module array-to-object-keys
 */
declare module array-to-object-keys {
    /**
     * Converts an array to an object with static keys and customizable values
     * @example
     * arrayToObjectKeys(["a", "b"])
     * // {a: null, b: null}
     * @example
     * arrayToObjectKeys(["a", "b"], "value")
     * // {a: "value", b: "value"}
     * @example
     * arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`)
     * // {a: "value for a #1", b: "value for b #2"}
     * @param {string[]} array Keys for the generated object
     * @param {valueGenerator|*} [valueGenerator=null] Optional function that sets the object values based on key and index
     * @returns {Object<string, *>} A generated object based on the array input
     */
    function default(array: string[], valueGenerator?: valueGenerator | any): {
        [key: string]: any;
    };
}

This looks fine, but the syntax highlighting in my VSCode looked suspicious.

image

The module name is not parsed correctly with those dashes. Semi-official sources like this one told me that module names need to be quoted.

Okay, I can fix this as long as JSDoc doesn’t mind!

- /** @module array-to-object-keys */
+ /** @module "array-to-object-keys" */

It worked, the TSD output looks legit now, but… what is this abomination?

image

The underscores in the file name were one of many impacts that told me that the @module annotation is the wrong place to hack in a fix for that.

So what do you recommend? Is this a case that should be included in tsd-jsoc?

Like:

moduleName = moduleName.includes("-") ? `"${moduleName}"` : moduleName

Or did I understand something wrong on my side?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
englercjcommented, Feb 13, 2019

Hopefully that fixes it up, got some other work I want to do and will do a release at some point.

1reaction
englercjcommented, Feb 13, 2019

Turns out unquoted modules are actually just namespaces, so I need to quote them all. Will fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the difference between declaring a module in ...
The quoted modules are ES6 modules, and need to be be imported using an import statement like import 'activedirectory';.
Read more >
[quotes] False positive with backtick in declare module #757
declare module '*.html' { const value: string; export default value; }. Expected Result No rule violations as those can't be backticks.
Read more >
Store and Declare Modules - VTScada
Most modules that you write will be either plugins or services. The name to be assigned to that module. Any legal name may...
Read more >
PEP 8 – Style Guide for Python Code
Consistency within one module or function is the most important. ... Hanging indents *may* be indented to other than 4 spaces. foo ...
Read more >
3. Using GHCi — Glasgow Haskell Compiler 9.4.4 User's Guide
1 and can be useful for some tooling users. 3.2.1. Modules vs. filenames¶. Question: How does GHC find the filename which contains module...
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