Is there a way of doing an import and an export of the same named variable, at the same time, in the same TypeScript file?
For instance, the following situation:
import { State as UIState } from './ui'
import { State as ConnectionState } from './connection'
export { State as UIState } from './ui'
export { State as ConnectionState } from './connection'
export type State = {
ui: UIState
connection: ConnectionState
}
To reduce writing cost, I would like to be able to write something like that:
export import { State as UIState } from './ui'
Any ideas?
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.
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.
We can create a module by using the export keyword and can use in other modules by using the import keyword. Modules import another module by using a module loader. At runtime, the module loader is responsible for locating and executing all dependencies of a module before executing it.
The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum. When exporting a module using export = , TypeScript-specific import module = require("module") must be used to import the module.
Is there a way of doing an import and an export of a the same named variable, at the same time, in the same TypeScript file
No. There is no JS module syntax for that.
Creating a "index.ts" file (or foo.ts) reduced the repetitive import/export. (I am not sure if this is a good solution)
export * from './product-form.component'
export * from './product-list.component'
Angular module
import { NgModule } from '@angular/core';
import * as c from './index';
export * from './index'
@NgModule({
declarations: [
c.ProductListComponent,
c.ProductFormComponent,
]
})
export class ProductModule { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With