Ranger
Ranger

Reputation: 1174

Organizing Classes/Modules Collectively in TypeScript

I'd like to use the format:

--models
----fooModel.ts
----barModel.ts
----gooModel.ts
----carModel.ts
----...etc
--services
----fooService.ts
----barService.ts
----...etc
--utilities
----fooUtility.ts
----barUtility.ts
----...etc

...To store my classes/etc, with one class per file. I'd then like to (ideally) group them up somehow, or reference them collectively, by folder. Either something like:

import {Models} from "../models";

Or create a new file called "_models.ts" that would look something like this:

export module Models {
  //reference fooModel
  //reference barModel
  //continue referencing
};

...That I could then reference such as:

import {Models} from "../models/_models.ts"

Is something like this possible? If so, how?

Upvotes: 2

Views: 1224

Answers (1)

krontogiannis
krontogiannis

Reputation: 1939

See Typescript Modules on how to wrap modules and combine all their exports using the syntax:

export * from "module"

I have added an example from the documentation:

//AllValidators.ts

export * from "./StringValidator"; // exports interface StringValidator
export * from "./LettersOnlyValidator"; // exports class LettersOnlyValidator
export * from "./ZipCodeValidator";  // exports class ZipCodeValidator

Upvotes: 1

Related Questions