如何在 Typescript 中显式导入接口?

How to import interface explicitly in Typescript?

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

@types/redis我有:

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

export interface RedisClient extends Commands<boolean>, EventEmitter {

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

import { RedisClient } from "redis";

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

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

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

import type { RedisClient } from "redis"

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