declare namespace exported_ns {
  declare export const bar1: number;
  declare const bar2: boolean;
  declare var bar3: string;
  declare function f(a: string): string;
  declare function f(a: number): number;
  declare type Baz = string;
  enum B { C, D }
  if (true) {} // unsupported
  export type Baz2 = string;
  export interface Baz3 {}
  export const CONSTANT = 'foo'; // unsupported
  export default CONSTANT; // unsupported
  declare module.exports: {foo: string}; // unsupported
  import React from 'react'; // unsupported
}

declare namespace empty {}
declare namespace type_only {
  type T = number;
}

export function exported_merged(x: string): string {
  return x;
}
declare namespace exported_merged {
  declare const foo: string;
  declare type T = string;
}
exported_merged.foo as empty; // error: string ~> empty
'' as exported_merged.T; // ok
1 as exported_merged.T; // error: number ~> string

export default function default_merged(x: string): string {
  return x;
}
declare namespace default_merged {
  declare const foo: string;
  declare type T = string;
}
default_merged.foo as empty; // error: string ~> empty
'' as default_merged.T; // ok
1 as default_merged.T; // error: number ~> string

export class ExportedMergedClass {}
declare namespace ExportedMergedClass {
  type T = string;
}
'' as ExportedMergedClass.T; // ok
1 as ExportedMergedClass.T; // error: number ~> string

declare class ExportedMergedDeclareClass {}
declare namespace ExportedMergedDeclareClass {
  type T = string;
}
'' as ExportedMergedDeclareClass.T; // ok
1 as ExportedMergedDeclareClass.T; // error: number ~> string

// Test declare export namespace syntax
declare export namespace direct_export_ns {
  declare const x: number;
  type T = string;
}

export {
  exported_ns,
  empty, // error: empty is type-only
};

export type {type_only, exported_ns as exported_ns_type_only};

exported_ns.bar1 as empty; // error: number ~> empty
exported_ns.bar2 as empty; // error: boolean ~> empty
exported_ns.bar3 as empty; // error: string ~> empty
exported_ns.f(3) as empty; // error: number ~> empty
1 as exported_ns.Baz; // error: number ~> string
1 as exported_ns.Baz2; // error: number ~> string
1 as exported_ns.Baz3; // error: number ~> interface {}
exported_ns.B.C as empty; // error: enum ~> empty
exported_ns.React; // error: prop-missing
exported_ns.CONSTANT as empty; // prop-missing

// Test direct_export_ns
direct_export_ns.x as empty; // error: number ~> empty
1 as direct_export_ns.T; // error: number ~> string
