Skip to content

Embedding types in module/namespace declarations #35030

Closed
@alshdavid

Description

@alshdavid

Search Terms

module namespace declaration rexporting

Suggestion

When trying to export types in an index.ts, currently one must redefine those types in the barrel.

e.g.

Consumer

import { myModule } from 'my-module'

function foo(bar: myModule.MyClass) {

}

MyModule

Currently developers must export their variables and export their types too, but types must be redeclared.

// my-module/index.ts
import * as myClass from './my-class';

export const myModule = {
  ...myClass
} 

export declare namespace myModule {
  export type MyClass<T> = myClass.MyClass<T>
}

Suggestion

Would be nice if developers could just embed the type in the namespace

// my-module/index.ts
import * as myClass from './my-class';

export const myModule = {
 ...myClass
} 

export declare namespace myModule {
  export types from './my-class'
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions