7

I have several classes in all.ts module:

export class TemperatureSensor {
    temperature: number;
}

export class Chasis {
    id: string;
    type: string;
    ambientTemperature: TemperatureSensor
}

export class Computer {
    model: string;
    serial: string;
    chasis: Chasis;
}

In another module I need to import all of them - I use

import * as models from 'all';

And I can access classes with new models.Computer() as the example.

Quesion: how can I import all classes from all.ts without namespace? So I'd like to use new Computer()?

koral
  • 2,807
  • 3
  • 37
  • 65

2 Answers2

4

That's not possible. Read here for the possible ways to import.

Your best option is to use named imports that specify what you need in the file:

import {Computer} from './all';

new Computer();
Community
  • 1
  • 1
David Sherret
  • 101,669
  • 28
  • 188
  • 178
1

You can deconstruct as in

import * as models from 'all';
const {Computer} = models;