【问题标题】:How to import interface explicitly in Typescript?如何在 Typescript 中显式导入接口?
【发布时间】:2021-03-03 14:42:11
【问题描述】:

我想知道如何在 typescript 中显式导入接口?

在@types/redis 我有:

export const RedisClient: new (options: ClientOpts) => RedisClient;

export interface RedisClient extends Commands<boolean>, EventEmitter {

当我在我的代码中添加以下导入时:

import { RedisClient } from "redis";

导入的是常量,而不是接口。

【问题讨论】:

    标签: typescript import node-redis


    【解决方案1】:

    从 Typescript 3.8 开始,您可以使用仅类型的导入和导出。

    在你的情况下,它看起来像这样:

    import type { RedisClient } from "redis"
    

    https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 2015-08-23
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多