Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  172] [ 6]  / answers: 1 / hits: 84670  / 8 Years ago, tue, march 29, 2016, 12:00:00

How can I import all types from certain file?



Let's say I have myClass.ts and otherClass.ts.
I want to import all classes from otherClass.ts.



I've seen few syntaxes for imports.



import ClassA, { ClassB, ClassC } from 'otherClass';

import * as foo from 'otherClass';

import foo = require('otherClass');

import 'rxjs/Rx';



  1. The first needs me to list everything. I'd like to import all types.


  2. The second syntax needs the namespace prefix: foo.ClassA.


  3. I understand that the last one is TypeScript 1.4, but still supported.




Is there something like the following?



import * from otherClass;
...
var x = new ClassA()


Also, what's the meaning of the { ... } and some of the types being outside and some inside?



The documentation doesn't hint anything such.


More From » typescript

 Answers
14

With ES6 modules, the closest thing available to what you want is a namespace import:



import * as foo from './otherClass';


The use it individual exports as



foo.ClassA


You can see the available kinds of imports in the import documentation.




Also, what's the meaning of the { ... } and some of the types being outside and some inside?




That's for importing named exports. You can read about that in the documentation I referenced or in my answer here.


[#62766] Sunday, March 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;