Hur man importerar ett gränssnitt uttryckligen i Typescript?


Jag undrar hur man importerar gränssnittet uttryckligen i TypeScript?

I @types/redis har jag:

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

export interface RedisClient extends Commands<boolean>, EventEmitter {

när jag lägger till följande import i min kod:

import { RedisClient } from "redis";

konstanten importeras, inte gränssnittet.

Svar #1

Från och med Typescript 3.8 kan du använda typ-endast import och export.

I ditt fall skulle det se ut så här:

import type { RedisClient } from "redis"

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