-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
Summary
- TypeScript Version: 3.6.4
- Expected behavior:
tsandd.tsyield a same result - Actual behavior:
tsandd.tsyield 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'.