我想知道如何在 typescript 中显式导入接口(interface)?
在@types/redis
中我有:
export const RedisClient: new (options: ClientOpts) => RedisClient;
export interface RedisClient extends Commands<boolean>, EventEmitter {
当我在代码中添加以下导入时:
import { RedisClient } from "redis";
导入的是常量,而不是接口(interface)。
最佳答案
从 Typescript 3.8 开始,您可以使用仅类型导入和导出。
在您的情况下,它看起来像这样:
import type { RedisClient } from "redis"
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html
关于typescript - 如何在 Typescript 中显式导入接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66459265/