首页 > 解决方案 > 从导出的 Typescript 命名空间导入接口

问题描述

我正在使用第三方库,它在其index.d.ts文件中的名称空间内导出接口。

export namespace Ns {
  interface Foo {
    ...
  }

  interface Bar {
    ...
  }

export namespace AnotherNs {
  interface Foo {
    ...
  }

  interface Bar {
    ...
  }

如何将接口 Foo 从命名空间之一导入我的代码?

执行以下操作会产生 ts 错误Cannot use namespace 'Ns' as a value.

import { Ns } from "lib";

const foo: Ns.Foo = ...;

标签: typescripttypescript-namespace

解决方案


推荐阅读