Skip to content

Allow variable merge with namespace when value of variable is a allowed merging declaration #45975

Closed
@FilipeBeck

Description

@FilipeBeck

Suggestion

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

It is not allowed merging namespace with variables. But, in some cases, it should be when the value itself is a allowed merging.

This is allowed:

function foo() {
  // ...
}
namespace foo {
  export const bar = 'bar'
}

class Foo {
  // ...
}
namespace Foo {
  export const bar = 'bar'
}

But this is not:

const foo = function() {
  // ...
}
namespace foo {
  export const bar = 'bar'
}

const Foo = class {
  // ...
}
namespace Foo {
  export const bar = 'bar'
}

As class A {... and const A = class {... are equivalent, it should compile with no erros.

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