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

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

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

import hashSum = require('hash-sum');
import shortid = require('shortid');

declare function shortid(): string
declare function hashSum(input): string

export function hashAny(seed?, ...argv): string
{
	if (!seed)
	{
		seed = shortid()
	}
	else if (typeof seed !== 'string')
	{
		seed = hashSum(seed)
	}

	return String(seed)
}

export default hashAny;

预期行为:

输出的js文件包含

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

实际行为:

缺少require hash-sum, shortid

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function hashAny(seed, ...argv) {
    if (!seed) {
        seed = shortid();
    }
    else if (typeof seed !== 'string') {
        seed = hashSum(seed);
    }
    return String(seed);
}
exports.hashAny = hashAny;
exports.default = hashAny;

实验链接:
相关问题:

rlcwz9us

rlcwz9us1#

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

mbzjlibv

mbzjlibv2#

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

相关问题