镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Exported type merged with 'export * as namespace...' only exports type meaning. #36792

Closed

Description

@rbuckton

Previously I liked using TS namespaces and declaration merging for creating FP-style modules, without needing the MyModule.T convention:

export type Foobar = { }

export namespace Foobar {
  export function doStuff(foobar: Foobar) { }
}
import { Foobar } from './Foobar'

Foobar.doStuff(fb)

Namespaces are not really the way to go any more, babel doesn't support them, they probably aren't tree-shakeable etc. But I was hoping that the export * as ns syntax could be > used as a replacement, like this:

export type Foobar = import('./Foobar').Foobar

// Or:
// export type { Foobar } from './Foobar'

export * as Foobar from './Foobar'

This seems to pass the nightly compiler, but the compiler only knows that Foobar is re-exported as a type, not a value. It would be great if the compiler could merge them into a combined value & type like with namespaces.

Originally posted by Joni Katajamäki (@katis) in #4813 (comment)

Activity

  1. changed the title [-]exported type merged with 'export * as namespace...' only exports type meaning.[/-] [+]Exported type merged with 'export * as namespace...' only exports type meaning.[/+] on Feb 13, 2020
  2. jasonkuhrt commented on Sep 1, 2021

    @jasonkuhrt

    We have certain projects/modules making heavy use of this pattern. The writing is on the wall though that we're in need of change:

    • no tree shaking support
    • eslint warnings by default
    • no support for re-exports/barrel-exports like modules (aka. TS namespaces since being introduced have not kept apace with module namespaces)

    I guess I don't have much to add to this issue, its well described, and our use-case is similar. I just wish I could +1000 it :)

  3. nexsodev commented on Oct 12, 2021

    @nexsodev

    Same here, my case:

    export * from './types/index.js';
    
    export {
      RequestContext,
      ResponsePayload,
    };

    In a:

    import { RequestContext,  } from '@ns/package';

    Only the options: RequestContext and ResponsePayload are showed, none of the types is present, but it works in runtime.

    types/index.js is:

    // ...
    export * from './client-error/index.js';
    export * from './server-error/index.js';
    
    export {
      GenericHttpError,
    };
  4. RyanCavanaugh commented on Sep 3, 2026

    @RyanCavanaugh
    Member

    This is fixed by #50853, which resolves aliases before checking their type/value meaning.

    With a top-level doStuff export in ./Foobar, the export type Foobar = import('./Foobar').Foobar and export * as Foobar from './Foobar' pattern produced TS2693 ('Foobar' only refers to a type, but is being used as a value here.) in 4.9.0-dev.20220929. It compiles without that diagnostic in the adjacent 4.9.0-dev.20220930 package and in current native TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: ES ModulesThe issue relates to import/export style module behaviorFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions