如何用预定字符串作为关键制作地图?

发布于 2025-01-18 19:40:57 字数 611 浏览 3 评论 0原文

我想在JSDOC中定义带有预定字符串的地图。例如:

/**
 * @typedef {'date' | 'string' | 'integer' | 'float' | 'currency' | 'description'} ColumnTypes
 * @type {Map<ColumnTypes, string>}
 */
typeMap = {
    'string': 'varchar(max)',
    'integer': 'decimal(18,4)',
    'date': 'smalldatetime',
}

我尝试这样写,但是我没有看到键的选项列表,例如我使用@type {columntypes}

typescript等效的是:

type ColumnTypes = ('datetime' | 'string' | 'integer' | 'decimal' | 'currency' | 'text')
type DatamapType = {
    [key in ColumnTypes]: string;
}

但是我不知道知道如何在JSDOC中写这篇文章。

谢谢

I want to define a map with predetermined strings in JSDoc. Such as:

/**
 * @typedef {'date' | 'string' | 'integer' | 'float' | 'currency' | 'description'} ColumnTypes
 * @type {Map<ColumnTypes, string>}
 */
typeMap = {
    'string': 'varchar(max)',
    'integer': 'decimal(18,4)',
    'date': 'smalldatetime',
}

I tried to write it like that, but I didn't see the options list for the keys like when I use @type {ColumnTypes}

A typescript equivalent would be:

type ColumnTypes = ('datetime' | 'string' | 'integer' | 'decimal' | 'currency' | 'text')
type DatamapType = {
    [key in ColumnTypes]: string;
}

But I don't know how to write that in jsdoc.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴梦一场 2025-01-25 19:40:57

以下内容可以做到这一点:

/**
 * @typedef {'date' | 'string' | 'integer' | 'float' | 'currency' | 'description'} ColumnTypes
 * @type {Record<ColumnTypes, string>}
 */
const typeMap = {
  'string': 'varchar(max)',
  'integer': 'decimal(18,4)',
  'date': 'smalldatetime',
  'float': 'float',
  'currency': 'currency',
  'description': 'description',
}

The following would do it:

/**
 * @typedef {'date' | 'string' | 'integer' | 'float' | 'currency' | 'description'} ColumnTypes
 * @type {Record<ColumnTypes, string>}
 */
const typeMap = {
  'string': 'varchar(max)',
  'integer': 'decimal(18,4)',
  'date': 'smalldatetime',
  'float': 'float',
  'currency': 'currency',
  'description': 'description',
}
最后的乘客 2025-01-25 19:40:57

你的语法有点不对劲。你可以这样写。
您可以从此处了解 jsdoc。

/**
  * @typedef {(string | number | Date )} ColumnTypes
  * @type {Map.<ColumnTypes, string>}
 */
 typeMap = {
  'string': 'varchar(max)',
  'integer': 'decimal(18,4)',
  'date': 'smalldatetime',
}

Your syntax is a little off. You can write it like this.
You can learn about jsdoc from here.

/**
  * @typedef {(string | number | Date )} ColumnTypes
  * @type {Map.<ColumnTypes, string>}
 */
 typeMap = {
  'string': 'varchar(max)',
  'integer': 'decimal(18,4)',
  'date': 'smalldatetime',
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文