小编Fel*_*nda的帖子

具有独特属性的 TypeScript 对象集

我简单地写了这样的接口:

interface IProduct {
  id: number;
  name: string;
  price: number;
  description?: string;
}
Run Code Online (Sandbox Code Playgroud)

现在我想id在 ReadonlyArray 中保持唯一。因此,当创建一些产品时,我想防止添加具有相同 id 的对象。包含产品的数组将在文件中创建一次,并且不会被修改。

你对此有什么想法吗?JS Set 将是一个很好的解决方案,但我无法向它们添加自己的比较器。请不要提供需要额外框架等的解决方案。

javascript set typescript

4
推荐指数
1
解决办法
2870
查看次数

无法验证 github 和 npm

 $ npm login --scope=@username --registry=https://npm.pkg.github.com
 
 $ Username: username
 
 $ Password: ********
 
 $ Email: (this IS public) example@gmail.com
 
 $ npm ERR! code E401
 
 $ npm ERR! 401 Unauthorized - PUT $ https://npm.pkg.github.com/-/user/org.couchdb.user:forinda - Error authenticating user: Requires authentication
 
 $npm ERR! A complete log of this run can be found in:
 
 $npm ERR!     /home/orinda/.npm/_logs/2021-10-15T02_25_19_104Z-debug.log
Run Code Online (Sandbox Code Playgroud)

无法验证 npm 注册表和 github 我在填写密码时收到 401 错误 如何解决此问题

github npm-request npm-publish

1
推荐指数
1
解决办法
2817
查看次数

标签 统计

github ×1

javascript ×1

npm-publish ×1

npm-request ×1

set ×1

typescript ×1