You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Essentially I want to group together various types from other files into one namespace X. So the types are not declared in namespace X, but they are later grouped into namespace X after the fact. Hopefully that makes sense.
A simple scenario would look like:
import{p}from'q';import{foo}from'bar';import{zim}from'zoom';exportnamespaceX{exportp;// this syntax is not real, don't know what the right exportfoo;// syntax is in actualityexportzim;}
we can sort of do this with a const:
exportconstX={
p,
foo,
zim
}
but the problem is, for interfaces, I get the error:
only refers to a type, but is being used as a value here.
You can often get around this with notion like this:
import {p as _p} from 'q';
import {foo as _foo} from 'bar';
import {zim as _zim} from 'zoom';
export namespace X {
export import p = _p;
export import foo = _foo;
export import zim = _zim;
}
or
import * as Q from 'q';
import * as Bar from 'bar';
import * as Zoom from 'zoom';
export namespace X {
export import p = Q.p;
export import foo = Bar.foo;
export import zim = Zoom.zim;
}
thanks yeah your solution works in general, but for interfaces, I get that error though "using as value, but only refers to a type", so I have to use the solution/answer that's in the StackOverflow link at the top.
The notation that I used works for me with interfaces/types too.
Example
TestInterfaces.ts
export interface I {a:number};
export type T = number|string;
TestLibrary.ts
import * as TestInterfaces from "./TestInterfaces";
export namespace X {
export import I = TestInterfaces.I;
export import T = TestInterfaces.T;
}
The problem exists if you try to do an aliased/selective import. The following will generate the error that you cite:
TestLibrary.ts
import {I as I2} from "./TestInterfaces";
import {T as T2} from "./TestInterfaces";
export namespace X2 {
export import I = I2;
export import T = T2;
}
An there is no pretty way to bundle these aliased interfaces/types unless you do something cumbersome like this:
TestLibrary.ts
import {I as I2} from "./TestInterfaces";
import {T as T2} from "./TestInterfaces";
export namespace X3 {
export interface I extends I2 {};
export type IAsType = I2;
export type T = T2;
}
I agree that just having a convenient re-export notation like you have stated would be optimum.
I also meant to say, if you want to keep the convenience of export const for re-exported objects/values, you can still conflate the namespace X after it with re-exported types/interfaces:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
ORESoftware commentedon Nov 26, 2017
I found a related issue - #4529
Not sure if that's the most recent on this.
[-]Exporting imported types as a namespace / module[/-][+]Exporting imported types as a namespace[/+]poseidonCore commentedon Nov 27, 2017
You can often get around this with notion like this:
or
ORESoftware commentedon Nov 27, 2017
thanks yeah your solution works in general, but for interfaces, I get that error though "using as value, but only refers to a type", so I have to use the solution/answer that's in the StackOverflow link at the top.
poseidonCore commentedon Nov 28, 2017
The notation that I used works for me with interfaces/types too.
Example
TestInterfaces.ts
TestLibrary.ts
The problem exists if you try to do an aliased/selective import. The following will generate the error that you cite:
TestLibrary.ts
An there is no pretty way to bundle these aliased interfaces/types unless you do something cumbersome like this:
TestLibrary.ts
I agree that just having a convenient re-export notation like you have stated would be optimum.
poseidonCore commentedon Nov 28, 2017
I also meant to say, if you want to keep the convenience of
export constfor re-exported objects/values, you can still conflate the namespace X after it with re-exported types/interfaces:But it's still not pretty.
typescript-bot commentedon Dec 12, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
ORESoftware commentedon Dec 12, 2017
I solved this problem with the accepted answer to this question:
https://stackoverflow.com/questions/47500855/exporting-imports-as-a-namespace-with-typescript