-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add "import *" like Python #2819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
With ES6 module syntax support you can write it as: import { foo, IOptions } from "foo";
var options: IOptions = {...};
var result = foo(options); |
Seems the ES6 module syntax is only supported by TypeScript 1.5, which is not released yet? |
TypeScript 1.5-alpha has been released, see https://github.com/Microsoft/TypeScript/releases/tag/v1.5.0-alpha for more details. |
@mhegazy but you still have to provide a list of names/aliases which is annoying if you have a file with lot of definitions. Instead it would be very useful to support a import { * } from "file"; Ideally the best syntax would be: import "file"; but as I see from #2242 it's already taken for "Bare Imports". Allowing import of whole files is a well established pattern (for example) in the Dart language. |
The only issue with |
@mhegazy it doesn't have to be different from what TypeScript is actually doing now. To be more clear, my suggestion is that: import { * } from "file"; // notice curly braces to became a shortcut for import { foo,bar } from "file"; Its only purpose should be to avoid to re-type names; it should not introduce any new behaviour. |
@teppeis if |
The idea is that you can process a module in isolation, without knowing anything about other modules.. in cases where you want the compile to bring all bindings in scope using import * from "mod1";
import * from "mod2";
a; we do not know if i understand this is a useful feature, TypeScript already supports something similar with |
@mhegazy thank you for the example, now it's more clear what is meant by "breaks single file scenarios". If the goal is avoiding scanning external files, then it makes sense to be forced to explicitly list names. |
How do you scan files when you are transpiling client side? It isn't a goal, it is a technical reality in some environments. |
As mentioned in #2819 (comment), the original issue should be handled by ES6 module syntax. |
the |
Sometimes a class/function has a few supporting small types, like the example below.
In foo.ts:
Then in another file:
This doesn't work because
IOptions
andIResult
have be exported too. But then you'll have to write:It's also possible to put
IOptions
andIResult
in separate files. But those two types are small and tightly coupled tofoo
, so it's easier to maintain them in the same file asfoo
. Also, you'll need to write 3 import statements to import them all.Why not support the following (like Python's
from module import *
)?In foo.ts:
Then in another file:
The text was updated successfully, but these errors were encountered: