如何在TypeScript中导入默认导出类型?

如何在TypeScript中导入默认导出类型?,typescript,Typescript,我想用下面的代码声明window.lottie //node_模块/lottie web/index.d.ts 类型LottiePlayer={ playname?:字符串:void; stopname?:字符串:void; setSpeedspeed:编号,名称?:字符串:无效; setDirectiondirection:AnimationDirection,名称?:字符串:void; SearchAnimationAnimationData?:任意、独立?:布尔、渲染器?:字符串:无效;

我想用下面的代码声明window.lottie

//node_模块/lottie web/index.d.ts 类型LottiePlayer={ playname?:字符串:void; stopname?:字符串:void; setSpeedspeed:编号,名称?:字符串:无效; setDirectiondirection:AnimationDirection,名称?:字符串:void; SearchAnimationAnimationData?:任意、独立?:布尔、渲染器?:字符串:无效; loadAnimationparams:AnimationConfigWithPath | AnimationConfigWithData:AnimationItem; destroyname?:字符串:void; registerAnimationelement:元素,animationData?:任意:无效; setQualityquality:字符串|编号:void; setLocationHrefhref:字符串:void; }; 声明const-Lottie:LottiePlayer; 导出默认乐透; 但是有一个错误

TS2749: 'Lottie' refers to a value, but is being used as a type here.
那么如何在TypeScript中导入默认导出类型呢?

declare const Lottie:LottiePlayer告诉我们,模块Lottie web导出的是LottiePlayer类型的对象,而不是类型

看起来你真的希望window.lottie是LottiePlayer类型

类型LottiePlayer不是从lottie web显式导出的。但是,使用typeof关键字,我们可以通过以下方式避开此问题:

import Lottie from 'lottie-web';

declare interface Window {
  lottie: typeof Lottie; //LottiePlayer
}
declare const Lottie:LottiePlayer告诉我们模块Lottie web导出的是LottiePlayer类型的对象,而不是类型

看起来你真的希望window.lottie是LottiePlayer类型

类型LottiePlayer不是从lottie web显式导出的。但是,使用typeof关键字,我们可以通过以下方式避开此问题:

import Lottie from 'lottie-web';

declare interface Window {
  lottie: typeof Lottie; //LottiePlayer
}