#Exporting a namespace of types from a sub-module

12 messages · Page 1 of 1 (latest)

rancid ice
#

We currently have a module which contains a bunch of types and one exported class.
This module is pulled into the main entrypoint (src/main.ts).

is there a way to essentially export type * as someNameSpace from './submod.js?

currently, even 5.x versions of typescript give some of our consumers this error:

error TS1383: Only named exports may use 'export type'.

i can't really work around it by some kind of namespace either since you can't export types in namespaces it seems (export namespace Foo { export type {A, B, C} from './submod.js'; })

#

i saw andrew did a PR a while back to allow export type * so im not sure why we get errors for this

fickle otter
#

why can't you just export * as someNameSpace?

wide flint
#

export type * as foo from "react"; works for me on v5.5.4 and greater

rancid ice
#

just coming back to this

#

we need to support slightly older typescript in parse5, and this export type * syntax accidentally introduced a breaking change

#

is there some way we could achieve the same using older syntax?

#

the same as export type * as foo from './submod.js'; (so foo is a namespace of all the types from submod)

wide flint
#

to be clear typescript does not follow semver, every version increment can and will often contain breaking changes

#
import type * as foo from "react";
export { foo };

perhaps?

#

export { type foo }; may be better