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

Docs: How to escape special characters in JSDoc property names #3

Open
coolaj86 opened this issue Aug 26, 2021 · 2 comments
Open

Docs: How to escape special characters in JSDoc property names #3

coolaj86 opened this issue Aug 26, 2021 · 2 comments

Comments

@coolaj86
Copy link
Collaborator

coolaj86 commented Aug 26, 2021

You'd never put # as an object name for a sane reason... but sometimes you have to deal with CSV. According to the JSDoc docs, it seems like this should do the job:

/**
 * @typedef {Object} EmpCsv
 * @property {string} Emp#
 * @property {string} "First Name"
 */

But I get errors...

Asked at https://stackoverflow.com/questions/68946492/how-can-i-escape-special-characters-names-in-jsdoc-typescript.

@coolaj86 coolaj86 changed the title document special characters in jsdoc Docs: How to escape special characters in JSDoc property names Aug 26, 2021
@coolaj86
Copy link
Collaborator Author

There's an alternate syntax that works:

/**
 * @typedef {{
 *   "Emp#": string,
 *   "First Name": string,
 * }} EmpCsv
 */

And the .d.ts counterpart should look like this:

interface EmployeeCsv {
  "Emp#": string,
  "First Name": string,
}

@dleetr
Copy link

dleetr commented Sep 21, 2023

Is there a way to add descriptions to a member with this alternate style? I cannot get vscode to be happy with any variation I attempt

/**
 * @typedef {{
 *   "Emp#": string, // want to give context to Emp# here
 *   "First Name": string,
 * }} EmpCsv
 */

I tried a couple of workarounds to no avail. Is there any functioning syntax where we can add normal, full-fledged annotation with description to a special character field name?

Edit: The best I've done so far is doing the jankiness below for the special character fields.

/**
 * @typedef FooHelperProps
 * @property {string} fooField - Can still annotate regular fields at least
 *
*/
/**
 * @typedef {FooHelperProps & {":specialField": any[]}} FooProps // Can't annotate ":specialField"
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants