如何为所有名称声明出口

时间:2019-04-07 02:00:36

标签: typescript

我想为Webpack加载的文件创建一个定义,以便TypeScript能够正确理解它。我正在尝试做这样的事情:

declare module "*.gql"
{
    import { DocumentNode } from "graphql";

    declare [key: string]: DocumentNode;
}

因此,任何来自.gql文件的命名导入都将具有DocumentNode类型。

import { MyQuery } from "./query.gql";
// MyQuery should have type DocumentNode

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我不知道是否为时已晚,但这是我的方法:

declare module '*.gql' {
  import {DocumentNode} from 'graphql';

  const value: DocumentNode;
  export = value;
}

还发现了这一点:

declare module '*.gql' {
  import { DocumentNode } from 'graphql';

  const value: {
    [key: string]: DocumentNode;
  };
  export = value;
}

go here