Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reexport class in Typescript

Tags:

typescript

I have two classes in two files.

//a.ts export class A{}  //b.ts export class B{} 

How I can build file c.ts from which I could import both classes?

import {A, B} from "c"; 

instead of

import {A} from "a"; import {B} from "b"; 

I want to make kind of export facade. How to reexport type?

like image 245
mleko Avatar asked Apr 22 '16 10:04

mleko


People also ask

What is export type in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

Can we export interface in TypeScript?

Use a named export to export an interface in TypeScript, e.g. export interface Person{} . The exported interface can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.

What is declare module in TypeScript?

The TypeScript declares module is one of the modules and keyword it is used for to surround and define the classes, interfaces; variables are also declared it will not originate with the TypeScript like that module is the set of files that contains values, classes, functions/methods, keywords, enum all these contains ...


1 Answers

I found answer by myself

https://www.typescriptlang.org/docs/handbook/modules.html @Re-exports

Code to do what I wanted

//c.ts export {A} from "a"; export {B} from "b"; 

Default export

Assuming you have file

//d.ts export default class D{} 

Re-export have to look like this

//reexport.ts export { default } from "d"; 

or

//reexport.ts export { default as D } from "d"; 

What happens here is that you're saying "I want to re-export the default export of module "D" but with the name of D

like image 183
mleko Avatar answered Oct 14 '22 03:10

mleko