TypeScript import * without creating aliases

In TypeScript, how do you “import” from a file without any aliases?

eg. I have a "utils" file with exported top-level functions and you want to import all of them without re-creating the aliases for each function.

Something like that:

import * from "utils";

Is it possible?

+4
source share
2 answers

I think the idea is to create a "Utils" module, attach all the functions and / or classes to it, export them and then export them, for example

module Utils {
    export function add(first:number, second:number):number {
        return first+second
    }
}
export = Utils

Although I haven't played with the es6 module syntax in typescript yet, as you seem to mean using it.

0
source

You are close:

import * as utils from 'utils';

No curly braces.

-1
source

Source: https://habr.com/ru/post/1599637/


All Articles