Skip to content
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

Automatically import module #8550

Closed
michaelmesser opened this issue May 10, 2016 · 9 comments
Closed

Automatically import module #8550

michaelmesser opened this issue May 10, 2016 · 9 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@michaelmesser
Copy link

Automatically import modules.
A.ts:

export const a = 2

B.ts:

const b = a + 2

Module B would automatically import module A.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented May 10, 2016

What do you mean exactly by automatically? Is this a language-service related quick-fix? Or is it something the compiler would figure out on its own?

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label May 10, 2016
@michaelmesser
Copy link
Author

I mean the compiler

@mhegazy mhegazy added Out of Scope This idea sits outside of the TypeScript language design constraints Too Complex An issue which adding support for may be too complex for the value it adds and removed Needs More Info The issue still hasn't been fully clarified labels May 10, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2016

The compiler can not implicitly figure out your imports. what if you have a global called a, what if you have multiple modules called a, what if it is just an error..
Modules do have a clear syntax for importing names into their scope.

@michaelmesser
Copy link
Author

If there any way to avoid importing 10 files at the top of every file?

import X from "./X.ts"
import Y from "./Y.ts"
...

Or to import a file/library project wide?

@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2016

you could reexport declarations.. e.g.:

// api.ts

// Things that every one needs
export * from "./x";
export * from "./y";
export * from "./z";
// module.ts

import { x, y, z} from "./api";

@michaelmesser
Copy link
Author

michaelmesser commented May 10, 2016

@mhegazy Thanks for your help. That work around will do. I was hoping for something like swift thought were imports happen automatically for the same project.

@michaelmesser
Copy link
Author

Is there a way to do import * from "./file.ts"?

@kitsonk
Copy link
Contributor

kitsonk commented May 11, 2016

import * as file from "./file.ts";

StackOverflow or gitter or ##typescript on IRC are really good places for these types of questions.

@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2016

As @kitsonk noted, import * as ns from "mod" is the recommended pattern. You can find more about what import * from "mod" was not considered in #2956 (comment)

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

4 participants