TypeScript 无法在覆盖声明时发出导入,

mspsb9vt  于 9个月前  发布在  TypeScript
关注(0)|答案(2)|浏览(86)

TypeScript版本: 3.2.0-dev.201xxxxx
搜索词:
代码

  1. import hashSum = require('hash-sum');
  2. import shortid = require('shortid');
  3. declare function shortid(): string
  4. declare function hashSum(input): string
  5. export function hashAny(seed?, ...argv): string
  6. {
  7. if (!seed)
  8. {
  9. seed = shortid()
  10. }
  11. else if (typeof seed !== 'string')
  12. {
  13. seed = hashSum(seed)
  14. }
  15. return String(seed)
  16. }
  17. export default hashAny;

预期行为:

输出的js文件包含

  1. const hashSum = require("hash-sum");
  2. const shortid = require("shortid");

实际行为:

缺少require hash-sum, shortid

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function hashAny(seed, ...argv) {
  4. if (!seed) {
  5. seed = shortid();
  6. }
  7. else if (typeof seed !== 'string') {
  8. seed = hashSum(seed);
  9. }
  10. return String(seed);
  11. }
  12. exports.hashAny = hashAny;
  13. exports.default = hashAny;

实验链接:
相关问题:

rlcwz9us

rlcwz9us1#

如果你声明了hash-sum模块(例如,在单独的文件中声明declare module 'hash-sum';),那么你会得到一个错误,Import declaration conflicts with local declaration of 'hashSum'.。关于导入是否在出现该错误的情况下发出,没有保证。我认为这个bug在于,当找不到模块时,你不会得到关于冲突的错误。

mbzjlibv

mbzjlibv2#

是的,即使理想情况下导入项 amy 未找到,我们仍应发出覆盖导入错误的错误。这可能是一个值得保留的后续错误。

相关问题