typescript - 如何在 Typescript 中显式导入接口(interface)?

标签 typescript import node-redis

我想知道如何在 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/

相关文章:

node.js - NPM 更新后 Aurelia Fetch 使用中断

node.js - 如何在 Redis 上命名空间键以避免名称冲突?

javascript - 使用前缀/通配符删除 Redis/Node

typescript - 平台特定的导入组件与 typescript native react

javascript - TypeScript 中带有配置对象的构造函数(如 jQuery.extend、Ext.apply)

Angular 2 : Component is not part of any module

java - 将 NetBeans(桌面应用程序)导入 Eclipse

android - 将现有的 Android 项目导入 Eclipse 重命名项目

reactjs - Vue.js 如何导入 SVG 标志

javascript - 将当前 session 存储在变量中以在 MySQL 查询中使用