microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.08k stars 12.49k forks source link

can't emit import when overwrite declare #28012

Open bluelovers opened 6 years ago

bluelovers commented 6 years ago

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms:

Code

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;

Expected behavior:

output js file include

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

Actual behavior:

miss 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;

Playground Link:

Related Issues:

mattmccutchen commented 6 years ago

If you declare the hash-sum module (e.g., declare module 'hash-sum'; in a separate file), then you get an error, Import declaration conflicts with local declaration of 'hashSum'. There are no guarantees on whether the import is emitted in the presence of that error. I think the bug is that you don't get the error about the conflict when the module can't be found.

weswigham commented 6 years ago

Aye, we should still be issuing the error that it overwrites the import even if the import is amy from being not found, ideally. This is probably a follow on error that's worth keeping.