Skip to content

No error in ts, but error in d.ts file when defining namespace sharing same name with a variable #34896

@samchon

Description

@samchon

Summary

  • TypeScript Version: 3.6.4
  • Expected behavior: ts and d.ts yield a same result
  • Actual behavior: ts and d.ts yield different results

When defining a namespace sharing same name with a variable and the namespace is designed only for type definition, it would be not an error in the ts file, but be an error in the d.ts file.

Detailed Story

Let's assume a special case. There's a namespace sharing same name with a variable. The namespace is designed only for definition; interfaces and types. If some of those definitions are exported and some of them are not exported, it would be an error in d.ts file, although the ts file does not occur any error.

On the other hand, if all of the definitions in the namespace are exported, there would not be any error in both ts and d.ts files. Whether the error occurs or not is dependent on the statement: export {};

Anyway, I don't know whether the action, defining namespace sharing same name with a variable, should be an error or not. But it seems weird that ts and d.ts files are saying different: one says not error, one says error.

No error in ts file

export const Something = {};
export namespace Something
{
    export interface IProps
    {
        nothing: INothing;
    }
    interface INothing
    {
        id: number;
        name: string;
    }
}

Error in d.ts file

export declare const Something: {};
export declare namespace Something {
    export interface IProps {
        nothing: INothing;
    }
    interface INothing {
        id: number;
        name: string;
    }
    export {};
}

Cannot redeclare block-scoped variable 'Something'.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions